Show / hide shipping methods based on order weightBesty
After adding this code snippet, you can either show or hide the required services in the cart. It shows/hides the shipping methods based on the order weight.
Add the following code to your functions.php or anywhere relevant.
If you are looking for a plugin to do this job, visit ELEX Hide Shipping Methods Plugin. Using this plugin, You can easily hide shipping methods based on various conditions.
In the above code, $order_weight stores the total weight of the order. Then it is converted to ounce (oz) and assigned to $weight_oz. If $weight_oz is less than or equal to 6 oz, then list all the services which need to be hidden in the $shipping_services_to_hide array. If the order weight is more than 6 oz, then save flat rate in the $shipping_services_to_hide array. For existing value of $shipping_services_to_hide unset it and return $available_shipping_methods.