dongqu2863
2017-10-14 20:57
浏览 840

WooCommerce - 使用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.

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.

图片转代码服务由CSDN问答提供 功能建议

我们正在对我们的WooCommerce进行一些自定义更改。

我们正在调用 成功:

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

产品 当我们点击购物车图标时,它会出现在购物车中。

然而,我无法弄清楚的是如何在前端自动触发当你出现的小型迷你购物车小工具 使用常规产品页面上的常规“添加到购物车”按钮。

我需要进行哪些其他调用才能获得与添加常规项目时相同的前端行为 购物车。

基本上,我只想向用户显示该项目 已成功添加到购物车。 它应显示项目已添加到购物车的消息,并在右上角更新购物车总数。

非常感谢任何帮助。

谢谢。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxun4924 2017-10-15 10:39
    已采纳

    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.

    打赏 评论

相关推荐 更多相似问题