Hello friends good morning, hope you are doing good today. Today, I am going to share very useful tips of WooCommerce based on WordPress platform. This tips will help you lot during the development of any WooCommerce websites. In this tutorial, you will hide shipping methods when free shipping available in WooCommerce based online store.
Sometimes online store owners want to hide all other shipping methods when free shipping is available during the check out process on the website.
Below snippet will hide all shipping methods if free shipping available for that order while checkout on the online store. Open your functions.php file and add the below snippets at the end of the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?php /** * woocommerce_package_rates is a 2.1+ hook */ add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 ); /** * Hide shipping rates when free shipping is available * * @param array $rates Array of rates found for the package * @param array $package The package array/object being shipped * @return array of modified rates */ function hide_shipping_when_free_is_available( $rates, $package ) { // Only modify rates if free_shipping is present if ( isset( $rates['free_shipping'] ) ) { // To unset a single rate/method, do the following. This example unsets flat_rate shipping unset( $rates['flat_rate'] ); // To unset all methods except for free_shipping, do the following $free_shipping = $rates['free_shipping']; $rates = array(); $rates['free_shipping'] = $free_shipping; } return $rates; } ?> |
If you still need any help, feel free to add your comments in below comment section. I will be happy to help. 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 and also don’t forget to subscribe my blog to get all future tutorials directly in your mail box.
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 tutorial, woocommerce tutorials, wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners, wordpress tutorials for beginners, wordpress woocommerce tutorial