我有一个使用 Divi 主题的 WordPress 网站。当我更新购物车中的商品数量时,标题上的迷你购物车没有相应更新。但是,迷你购物车中的商品数量会在重新加载页面时更新。
Divi 正在使用以下函数来更新购物车,
if ( ! function_exists( 'et_show_cart_total' ) ) {
function et_show_cart_total( $args = array() ) {
if ( ! class_exists( 'woocommerce' ) || ! WC()->cart ) {
return;
}
$defaults = array(
'no_text' => false,
);
$args = wp_parse_args( $args, $defaults );
$items_number = WC()->cart->get_cart_contents_count();
$url = function_exists( 'wc_get_cart_url' ) ? wc_get_cart_url() : WC()->cart->get_cart_url();
printf(
'<a href="%1$s" class="et-cart-info">
<span>%2$s</span>
</a>',
esc_url( $url ),
( ! $args['no_text']
? esc_html( sprintf(
_nx( '%1$s Item', '%1$s Items', $items_number, 'WooCommerce items number', 'Divi' ),
number_format_i18n( $items_number )
) )
: ''
)
);
}
}
如何通过 ajax 调用更新购物车中的商品数量来更新迷你购物车? 请问有人可以帮忙吗?
最佳答案
请在您的functions.php文件中尝试以下代码
add_filter( 'woocommerce_add_to_cart_fragments', 'your_custom_functions', 10, 1 );
function your_custom_functions( $fragments ) {
$fragments['.your_cart_class'] = '' . WC()->cart->get_cart_contents_count() . ' Items';
return $fragments;
}
关于ajax - 使用 divi 的 header 迷你购物车在更改购物车商品计数时未更新 : Wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48536949/