If your Divi theme is not updating the menu header WooCommerce cart count when you add an item via AJAX there’s a fix. Use the following WooCommerce snippet to ensure the cart contents count is updated in the Divi navigation menu having to refresh the page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/** * Refresh WooCommerce fragments for Divi cart count. * * @param array $fragments * @return void */ function es_fresh_cart_fragments($fragments) { ob_start(); et_show_cart_total(); $cart_total_html = ob_get_clean(); $fragments['.et-cart-info'] = $cart_total_html; return $fragments; } add_filter('woocommerce_add_to_cart_fragments', 'es_fresh_cart_fragments', 10, 1); |
The trick here to ensure the cart keep the same Divi cart count layout is to use the et_show_cart_total() function. Furthermore, we buffer the output that this aforementioned function generates in order to update the WooCommerce fragments.