-
-
Save mikejolley/2044109 to your computer and use it in GitHub Desktop.
WooCommerce - Update number of items in cart and total after Ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php) | |
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' ); | |
function woocommerce_header_add_to_cart_fragment( $fragments ) { | |
ob_start(); | |
?> | |
<a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf (_n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a> | |
<?php | |
$fragments['a.cart-contents'] = ob_get_clean(); | |
return $fragments; | |
} |
Update count when cart page with ajax update.
jQuery(document.body).on('removed_from_cart updated_cart_totals', function () {
$(document.body).trigger('wc_fragment_refresh');
});
@rajanvijayan Working perfectly. Thank you.
Please auttakaa joku en tiedä onko tämä oikea paikka kysyä mutta minun Supercell ID on lukittu ja kun yritän mennä sinne uudella sähköpostilla ja id:llä tulee vaan anna palautuskoodit mistä mä voin löytää ne koodit ja miten mä voin päästä sinne omalle tilille ne takaisin kyseessä on hay day koodit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not work on cart page and how to fix easy way?