0
votes

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.

Example of what should display

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.

1

1 Answers

1
votes

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.