WooCommerce Show cart items on help page

I am working on this site where I was asked to add a list of cart items to the checkout page. I decided to add

[woocommerce_cart] 

shortcode to check page, above

 [woocommerce_checkout] 

and just use CSS to hide the "Proceed to check →" button in the trash on the checkout page.

However, this introduced a new problem. Now that delivery is selected on the Checkout page, it defaults to which delivery was set for the basket on the Cart page ... even if a new delivery is selected on the check page.

Obviously, this is not a way to add basket output to the checkout page.

Is there a short code to show cart items themselves?

What do I need to change to display cart items on the verification page?

+6
source share
3 answers

I am going to answer my own question, since I solved it with some extra feather grass. Hope this helps someone else along the way.

I did not find the code to simply add the basket 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 

in

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

to make my changes to this file directly so that I don’t lose them when updating WooCommerce. Then I copied the form code from:

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

And pasted it into a file that I copied to my themes directory:

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

where do i need a form.

There may be more elegant ways, but that fixed my problem.

+15
source

You can also use 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 created a cart-part.php template that contains the jus basket table and replaced the code wc_get_template_part ('cart / cart', 'part');

+3
source

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

This way you will not need to add any templates or modify any basic 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'); 
0
source

Source: https://habr.com/ru/post/958939/


All Articles