简体   繁体   中英

WooCommerce - Display updated mini cart widget with updated cart contents/totals after using add_to_cart

We are doing some custom changes to our WooCommerce.

We are calling successfully:

WC()->cart->add_to_cart($PRODUCT_ID)

The product appears in the cart when we click on the cart icon.

However, what I cannot figure out is how to trigger automatically on the front-end the small mini-cart widget that appears when you use the regular 'Add to Cart' button on regular product pages.

What other calls do I need to make to have the same front-end behavior that occurs when you add a regular item to the cart.

应显示内容的示例

Basically, I want to just show the user that the item was successfully added to the cart. It should display the message that the item was added to the cart and update the cart total in the top right corner.

Any help greatly appreciated.

Thank you.

So you are adding product to cart through you custom code and want to update the mini cart at the sane time. So you must be adding the product to cart on some ajax event, and then displaying the message. What you have to do is use wc_get_template function of woocommerce and load the mini-cart.php template and return this template html to your ajax request and as soon as ajax is successful output this html into the mini cart container. It will update the quantities and subtotal as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM