Woocommerce Get Active Shipping Methods At Checkout

Relevant Plugins Used: WooCommerce (3.2.5) , WooCommerce Custom Fields (2.2.3) by RightPress

I would like to show/hide custom fields by active shipping methods in my final checkout form. To do that I need to loop through the active shipping methods, which is configurable by future user in WooCommerce Settings.

I’ve looked at http://woocommerce.wp-a2z.org/oik_api/wc_trackerget_active_shipping_methods/ and see there’s such an API, yet when I tried this in my child theme functions.php, it doesn’t work (console logs nothing):

add_action( ‘woocommerce_after_checkout_form’, ‘my_load_available_shipping_methods’, 10, 0);
function my_load_available_shipping_methods() {?>
<script type=”text/javascript”>
foreach ( WC_Tracker::get_active_shipping_methods() as $id => $shipping_method ) { ?>
console.log(“<?php $id.’t’.$shipping_method ?>”);
<?php } ?>
<?php }

I’m also not very experienced with php (as you might already see) and extra explanation is greatly appreciated.

Read more here:: Woocommerce Get Active Shipping Methods At Checkout

Leave a Reply

Your email address will not be published. Required fields are marked *