I have tried to implement code found on this site in a number of answers from a particular user with regard to refreshing the checkout based on a change to the payment gateway selected or to some other field change. However, when the JS is included in my function file, my checkout is stuck and I have ajax loading animated circles.
I've already tried to adapt code from:
Trigger ajax update_checkout event on shipping methods change in Woocommerce
Update checkout ajax event when choosing a payment gateway in Woocommerce
On country change ajax update checkout for shipping in Woocommerce
Change Pay button on checkout based on Woocommerce chosen payment method
add_filter( "woocommerce_product_get_tax_class", "woo_diff_rate_for_user", 1, 2 );
add_filter( "woocommerce_product_variation_get_tax_class", "woo_diff_rate_for_user", 1, 2 );
function woo_diff_rate_for_user( $tax_class, $product ) {
// Get the chosen payment gateway (dynamically)
$chosen_payment_method = WC()->session->get('chosen_payment_method');
if( $chosen_payment_method == 'wdc_woo_credits'){
$tax_class = "Zero rate";
}
<script type="text/javascript">
(function($){
$('form.checkout').on( 'change', 'input[name^="payment_method"]', function() {
var t = { updateTimer: !1, dirtyInput: !1,
reset_update_checkout_timer: function() {
clearTimeout(t.updateTimer)
}, trigger_update_checkout: function() {
t.reset_update_checkout_timer(), t.dirtyInput = !1,
$(document.body).trigger("update_checkout")
}
};
$(document.body).trigger('update_checkout')
});
})(jQuery);
</script>
return $tax_class;
}
If I don't include the JS/jQuery, my function, which changes the tax class based on payment option works when the shipping method is changed and the page refreshes on change. But I need the checkout to refresh when the payment gateway is changed not when the shipping is changed.