duanna2026
duanna2026
2016-10-11 01:42

Woocommerce添加到购物车ajax和迷你购物车

  • wordpress
  • php
  • ajax

I need to re-populate mini-cart when product added via ajax add to cart. I manage to update cart quantity with filter woocommerce_add_to_cart_fragments like this:

add_filter( 'woocommerce_add_to_cart_fragments', function($fragments) {

    ob_start();
    ?>

    <div class="cart-contents">
        <?php echo WC()->cart->get_cart_contents_count(); ?>
    </div>

    <?php $fragments['div.cart-contents'] = ob_get_clean();

    return $fragments;

} );

And my HTML markup is

<div class="cart-contents">
    <?php echo WC()->cart->get_cart_contents_count(); ?>
</div>

Bellow that is hidden div witch showing on .cart-contents hover

<div class="header-quickcart"><?php woocommerce_mini_cart(); ?></div>

I want to update this div content same way or similar to woocommerce_add_to_cart_fragments. Or should I change HTML markup and hold everything in 1 div? What is common way or best practice to doing that?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐