The above code did not work correctly for me!
In the following code, if the cancel button is selected, the radio button will return to the previous state.
The following code was executed correctly:
add_action( 'woocommerce_review_order_before_payment', 'refresh_payment_methods' );
function refresh_payment_methods(){
$chosen_payment_method = WC()->session->get('chosen_payment_method');
?>
<script type="text/javascript">
var j_method = <?='"'. $chosen_payment_method .'"'?>;
(function($){
$( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function(event) {
var payment_method = $('form.checkout').find('input[name^="payment_method"]:checked').val();
if(payment_method == 'cod')
{
var method_select = confirm( 'Are you sure ?' );
if( method_select )//OK:
setTimeout(function(){$('body').trigger('update_checkout'); }, 250 );
else//Cancel:
$( '#payment_method_' + j_method ).prop('checked',true);
}else{
setTimeout(function(){$('body').trigger('update_checkout'); }, 250 );
}
//set new value
j_method = $('form.checkout').find('input[name^="payment_method"]:checked').val();
});
})(jQuery);
</script>
<?php
}