My goal is to show the popup when there is no shipping method available.
I know to use trigger updated_checkout
but how do I know from that trigger, the shipping method is not available?. so I can trigger to show the popup.
CodePudding user response:
You can trigger update_checkout
using $( 'body' ).on( 'updated_checkout',function( data ){});
Try the below code.
function check_shipping_method_available(){
?>
<script type="text/javascript">
(function( $ ) {
$( 'body' ).on( 'updated_checkout',function( data ){
if( !$('.shipping_method').length ){
alert('No Shipping method available');
// popup code
}
} );
})(jQuery);
</script>
<?php
}
add_action( 'wp_footer', 'check_shipping_method_available', 10, 1 );
Tested and works