woocommerce offtopic - Mini cart in header using divi is not getting updated on changing the cart items count:

I am having a wordpress site which is using the Divi theme. When I update the number of items in the cart, the mini cart

I am having a wordpress site which is using the Divi theme. When I update the number of items in the cart, the mini cart on the header is not getting updated accordignly. However, the number of items in the mini cart are getting updated on re-loading the page.

Divi is using the below function for updating the cart,

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 ) 
                               ) ) 
                               : '' 
                       ) 
               ); 
       } 
}

How can I update the mini cart on updating the number of items in the cart on ajax call?

Please can anyone help?

I am having a wordpress site which is using the Divi theme. When I update the number of items in the cart, the mini cart on the header is not getting updated accordignly. However, the number of items in the mini cart are getting updated on re-loading the page.

Divi is using the below function for updating the cart,

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 ) 
                               ) ) 
                               : '' 
                       ) 
               ); 
       } 
}

How can I update the mini cart on updating the number of items in the cart on ajax call?

Please can anyone help?

Share Improve this question asked Jan 31, 2018 at 8:23 devgeekdevgeek 1611 silver badge5 bronze badges 3
  • Did you added global $woocmmerce ? – DHL17 Commented Jan 31, 2018 at 11:32
  • Try as DHL17 is suggesting. – Aftab H. Commented Jan 31, 2018 at 12:16
  • Thanks but I kind of fixed my issue as per my answer below. – devgeek Commented Feb 2, 2018 at 6:32
Add a comment  | 

1 Answer 1

Reset to default 4

I fixed the issue by adding the below in my 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; 
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745156405a4614146.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信