php - Refresh Mini cart on shipping or payment method change in WooCommerce checkout
one text
Solution:
Try to use the following instead, delegating the change event to document.body
and targeting specifically shipping methods and payment methods changes:
add_action('wp_footer', 'minicart_checkout_refresh_script');
function minicart_checkout_refresh_script(){
if ( is_checkout() && ! is_wc_endpoint_url() ) :
?>
<script type="text/javascript">
(function($){
$(document.body).on('change', 'input[name="payment_method"],input[name^="shipping_method"]', function(){
$(document.body).trigger('update_checkout').trigger('wc_fragment_refresh');
});
})(jQuery);
</script>
<?php
endif;
}
Code goes in functions.php file of the active child theme (or active theme). It should better work.
SourceNote: There is not any calculated total in mini cart, but only cart items subtotal… You can see that on WooCommerce default template
file. So there is nothing to be refreshed or updated in default WooCommerce mini cart on checkout page.