简体   繁体   English

WooCommerce-使用add_to_cart后显示具有更新的购物车内容/总计的更新的迷你购物车小部件

[英]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. 我们正在对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. 因此,您必须在某个ajax事件中将产品添加到购物车,然后显示消息。 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. 您需要做的是使用woocommerce的wc_get_template函数并加载mini-cart.php模板,然后将此模板html返回到您的ajax请求中,一旦ajax成功将其输出到迷你购物车容器中即可。 It will update the quantities and subtotal as well. 它将更新数量和小计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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