How to display WooCommerce cart items on the checkout page? How to display WooCommerce cart items on the checkout page? wordpress wordpress

How to display WooCommerce cart items on the checkout page?


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.


You can also use a hook for this

// put this in functions.php, it will produce code before the formadd_action('woocommerce_before_checkout_form','show_cart_summary',9);// gets the cart template and outputs it before the formfunction show_cart_summary( ) {  wc_get_template_part( 'cart/cart' );}

I've created a cart-part.php template which contains jus the cart table and replaced the code with wc_get_template_part( 'cart/cart','part' );


An easier way to do this is by adding the following code into your functions.php file in your child theme.

This way you will not need to add any templates or alter any core woocommerce code.

function remove_cart_collaterals() {    if (is_checkout()) {        remove_action('woocommerce_cart_collaterals', 'woocommerce_cross_sell_display');        remove_action('woocommerce_cart_collaterals', 'woocommerce_cart_totals', 10);    }}add_action('wp', 'remove_cart_collaterals');