Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 更改购物车项目计数时,使用divi的购物车标题未得到更新:Wordpress_Ajax_Wordpress_Cart - Fatal编程技术网

Ajax 更改购物车项目计数时,使用divi的购物车标题未得到更新:Wordpress

Ajax 更改购物车项目计数时,使用divi的购物车标题未得到更新:Wordpress,ajax,wordpress,cart,Ajax,Wordpress,Cart,我有一个使用Divi主题的wordpress网站。当我更新购物车中的商品数量时,标题上的迷你购物车没有相应地更新。但是,在重新加载页面时,迷你购物车中的项目数量会得到更新 Divi正在使用以下功能更新购物车 if ( ! function_exists( 'et_show_cart_total' ) ) { function et_show_cart_total( $args = array() ) { if ( ! class_exists( '

我有一个使用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 ) 
                               ) ) 
                               : '' 
                       ) 
               ); 
       } 
}
如果(!function_存在('et_show_cart_total'){
函数et_show_cart_total($args=array()){
如果(!class_存在('woocommerce')| |!WC()->cart){
返回;
} 
$defaults=数组(
“无文本”=>false,
); 
$args=wp\u parse\u args($args,$defaults);
$items_number=WC()->cart->get_cart_contents_count();
$url=函数_存在('wc_get_cart_url')?wc_get_cart_url():wc()->cart->get_cart_url();
printf(
'', 
esc_url($url),
(!$args['no_text']
?esc_html(sprintf(
_nx(“%1$s项目”、“1$s项目”、“$Items\u编号”、“WooCommerce项目编号”、“Divi”),
编号\u格式\u i18n($items\u编号)
) ) 
: '' 
) 
); 
} 
}
如何在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; 
}

你太棒了。。你救了我一天。非常感谢:)