我们正在使用WP Cart Menu Pro,在我们的商店页面上,我们将Ajax添加到购物车,该工作正常,但不会更新购物车菜单中的商品。
自动更新到WooCommerce 3.0.8后才开始发生这种情况。我做了一些研究,并将以下代码添加到我们的functions.php页面:
function my_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?><a class="wpmenucart-contents" href="https://www.springbokbbq.co.uk/cart/" title="View your shopping cart">
<i class="wpmenucart-icon-shopping-cart-5"></i>
<span class="cartcontents"><?php echo sprintf (_n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?></span>
</a><?php
$fragments['a.wpmenucart-contents'] = ob_get_clean();
return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'my_header_add_to_cart_fragment' );
是否有其他人在使用Woo更新时遇到过这个问题?
编辑:
我检查了Chrome控制台:当我点击添加到购物车时,我收到此错误:
Uncaught TypeError: a(...).addClass(...).fadeTo(...).block is not a function
at String.<anonymous> (add-to-cart.min.js?ver=3.0.8:4)
at Function.each (jquery.js?ver=1.12.4:2)
at HTMLDocument.b.updateFragments (add-to-cart.min.js?ver=3.0.8:4)
at HTMLDocument.dispatch (jquery.js?ver=1.12.4:3)
at HTMLDocument.r.handle (jquery.js?ver=1.12.4:3)
at Object.trigger (jquery.js?ver=1.12.4:3)
at Object.a.event.trigger (jquery-migrate.min.js?ver=1.4.1:2)
at HTMLBodyElement.<anonymous> (jquery.js?ver=1.12.4:3)
at Function.each (jquery.js?ver=1.12.4:2)
at a.fn.init.each (jquery.js?ver=1.12.4:2)
我从购物车中删除商品时没有收到此错误,它会更新购物车页面上的菜单购物车项目。