How to display WooCommerce cart items on the checkout page?

13,118

Solution 1

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.

Solution 2

You can also use a hook for this

// put this in functions.php, it will produce code before the form
add_action('woocommerce_before_checkout_form','show_cart_summary',9);

// gets the cart template and outputs it before the form
function 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' );

Share:
13,118
Yazmin
Author by

Yazmin

Updated on June 14, 2022

Comments

  • Yazmin
    Yazmin almost 2 years

    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?