dongqu2863 2017-10-14 20:57
浏览 888
已采纳

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.

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度