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.

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

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试