In this tutorial, I am going to share WooCommerce tricks which helps you if you want to hide other shipping methods if free shipping method is available on your WooCommerce store.
Copy the below code and add it at the end of the functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php add_filter( 'woocommerce_package_rates', 'hide_available_shipping_method', 100 ); function hide_available_shipping_method( $rates ) { $free = array(); foreach ( $rates as $rate_id => $rate ) { if ( 'free_shipping' === $rate->method_id ) { $free[ $rate_id ] = $rate; break; } } //this will return only free shipping method return ! empty( $free ) ? $free : $rates; } ?> |
I hope this tutorial helps you, if you have any questions regarding WordPress, then feel free to put your comments in below comment section. Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: woocommerce free shipping, woocommerce shipping method, woocommerce snippet, woocommerce snippets, wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners