I'm using woocommerce_after_shipping_rate
hook to add my codes, some PHP, some JS. On normal page load, all of my codes are loaded perfectly. But when I add/remove items from cart, or update my address at shipping calculator, which caused an update at the available shipping methods (using AJAX), my JS codes are not loaded.
Probably this is just a very basic thing I missed. Here's a simple version of my code:
function abc( $method, $index ) {
echo "This loaded on AJAX just fine";
echo "<script type='text/javascript'>";
echo "var a = 'This is NOT loaded on AJAX call, along with the tags above and below this';";
echo "</script>";
echo "This also loaded on AJAX just fine";
}
add_action( 'woocommerce_after_shipping_rate', 'abc', 10, 2 );
In case anyone wondered, my JS code is to put some variables which my JS function at the page header needs. The variables are based on the available shipping method currently loaded.
What I hope can be achieved is for my JS code to also be loaded on AJAX.
Any help is appreciated. Thanks.