Created
March 26, 2025 09:27
-
-
Save wplit/75d7501e242b98c0fc14fcf6b1ef9a02 to your computer and use it in GitHub Desktop.
ensure 'wc_fragment_refresh' is triggered when woocommerce add to cart blocks are used.
This file contains hidden or 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 | |
add_action( 'wp_enqueue_scripts', 'ensure_wc_cart_fragments', 20 ); | |
function ensure_wc_cart_fragments() { | |
wp_enqueue_script( 'wc-cart-fragments' ); | |
} | |
add_action('wp_enqueue_scripts', 'custom_enqueue_cart_refresh_script'); | |
function custom_enqueue_cart_refresh_script() { | |
wp_add_inline_script('wc-cart-fragments', " | |
document.addEventListener('wc-blocks_added_to_cart', function(event) { | |
jQuery(document.body).trigger('wc_fragment_refresh'); | |
}); | |
"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment