Yazmin Yazmin - 1 month ago 29
PHP Question

WooCommerce Show Cart Items on Checkout Page

I'm working on this website where I was asked to add a list of the cart items to the checkout page. I decided to add the

[woocommerce_cart]


shortcode to the checkout page, above the

[woocommerce_checkout]


shortcode and simply use CSS to hide the "Proceed to Checkout ->" button in the cart on the checkout page.

However, this has introduced a new problem. Now when shipping is selected on the Checkout page, it defaults to whatever shipping was set for the cart on the Cart page... even when new shipping is selected on the checkout page.

Clearly, this was not the way to add the cart output to the checkout page.

Is there a shortcode just to show the cart items themselves?

What do I need to edit to show the cart items on the checkout page?

Answer

I'm going to answer my own question, since I solved it with some additional poking around. Hopefully it will help someone else later down the road.

I didn't find a shortcode to to simply add the cart to the top of the checkout page. I had to edit the template file directly.

So, I copied:

/wp-content/plugins/woocommerce/templates/checkout/form-checkout.php

to:

/wp-content/mytheme/woocommerce/checkout/form-checkout.php

to make my edits to that file directly so I wouldn't lose them when WooCommerce was upgraded. I then copied the form code from:

/wp-content/plugins/woocommerce/templates/cart/cart.php

And pasted it in the file I copied to my theme directory:

/wp-content/mytheme/woocommerce/checkout/form-checkout.php

where I wanted the form to appear.

There may be more elegant ways, but this fixed my issue.

Comments