{"id":605,"date":"2019-12-03T03:38:31","date_gmt":"2019-12-03T03:38:31","guid":{"rendered":"http:\/\/shaplakanon.com\/wpsupport\/?p=605"},"modified":"2019-12-03T03:38:34","modified_gmt":"2019-12-03T03:38:34","slug":"how-to-hide-shipping-methods-for-specific-shipping-class-in-woocommerce","status":"publish","type":"post","link":"https:\/\/shaplakanon.com\/wpsupport\/how-to-hide-shipping-methods-for-specific-shipping-class-in-woocommerce\/","title":{"rendered":"How to hide shipping methods for specific shipping class in WooCommerce"},"content":{"rendered":"\n
Are you finding ways to hide shipping methods when Free Shipping is enabled? Trying to hide shipping methods for Shipping Classes ?<\/p>\n\n\n\n
There are many plugins for this which will cost you $$$.<\/p>\n\n\n\n
Here we will discuss, how you can do it free.<\/p>\n<\/div>\n\n\n\n
https:\/\/stackoverflow.com\/questions\/47718180\/hide-shipping-methods-for-specific-shipping-class-in-woocommerce<\/a><\/p>\n\n\n\n Need Help? Contact us at fb.me\/getwpsupport<\/strong> <\/p>\n<\/div>\n<\/div>\n\n\n\n Open your themes functions.php file and insert the below code<\/p>\n\n\n\n Replace 100 with your original class id<\/p>\n\n\n\n Finding the shipping class ID.<\/strong><\/p>\n\n\n\n 1) In the database under Search for a term name or a term slug and you will get the term ID (the shipping class ID).<\/p>\n\n\n\n Replace flat_rate:7, local_pickup:3 with your shipping methods name that you would like to hide.<\/p>\n\n\n\n To get the related\u00a0shipping methods rate IDs<\/strong>, something like\u00a0 Are you finding ways to hide shipping methods when Free Shipping is enabled? Trying to hide shipping methods for Shipping<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[176],"tags":[185,98],"class_list":["post-605","post","type-post","status-publish","format-standard","hentry","category-woocommerce","tag-shipping-class","tag-woocommerce"],"yoast_head":"\nadd_filter( 'woocommerce_package_rates', 'hide_shipping_method_based_on_shipping_class', 10, 2 );\nfunction hide_shipping_method_based_on_shipping_class( $rates, $package )\n{\n if ( is_admin() && ! defined( 'DOING_AJAX' ) )\n return;\n\n \/\/ HERE define your shipping class to find\n $class = 100;\n\n \/\/ HERE define the shipping methods you want to hide\n $method_key_ids = array('flat_rate:7', 'local_pickup:3');\n\n \/\/ Checking in cart items\n foreach( $package['contents'] as $item ) {\n \/\/ If we find the shipping class\n if( $item['data']->get_shipping_class_id() == $class ){\n foreach( $method_key_ids as $method_key_id ){\n unset($rates[$method_key_id]); \/\/ Remove the targeted methods\n }\n break; \/\/ Stop the loop\n }\n }\n return $rates;\n}<\/pre>\n\n\n\n
wp_terms<\/code> table:<\/p>\n\n\n\n
flat_rate:<\/code><\/strong>7, inspect with your browser code inspector each related radio button attribute\u00a0
name<\/code><\/strong>\u00a0like:<\/p>\n\n\n\n
<\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"