[vc_cta h2=”The Below Code Works for the Following Plugins:”]
- WooCommerce UPS Shipping plugin
- WooCommerce FedEx Shipping plugin
- WooCommerce Canada Post Shipping plugin
- WooCommerce Multi-Carrier Shipping plugin
- WooCommerce Table Rate Shipping Pro plugin
- ELEXtensions.com Shipping Plugins
[/vc_cta]
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 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 sto_hide unset it and return $available_shipping_methods.
Hi Gil,
I’ve added a code on your site, Please check if that works.
Regards,
Lorenzo
Team Xadapter
This is what I have in order to hide UPS Freight options on orders below 150 lbs, but it’s not hiding the Freight options. Please help.
add_filter( ‘woocommerce_package_rates’, ‘show_shipping_method_on_order_weight’, 10, 2 );
function show_shipping_method_on_order_weight( $available_shipping_methods, $package ) {
$order_weight = 0;
foreach( WC()->cart->cart_contents as $key => $values ) {
$product_weight = woocommerce_get_weight($values[ ‘data’ ]->get_weight(),’lbs’);
$quantity = $values[‘quantity’];
if($product_weight && $quantity){
$order_weight = $order_weight + $product_weight*$quantity;
}
}
$weight_oz = $order_weight*16;
if($weight_oz <= 2400){
$shipping_services_to_hide = array(
'wf_shipping_ups:308',
'wf_shipping_ups:14',
);
}else{
$shipping_services_to_hide = array(
'wf_shipping_ups:334',
'wf_shipping_ups:13',
'wf_shipping_ups:01',
'wf_shipping_ups:03',
'wf_shipping_ups:02',
'wf_shipping_ups:12',
);
}
foreach ( $shipping_services_to_hide as &$value ) {
unset( $available_shipping_methods[$value] );
}
return $available_shipping_methods;}
This is what I have in order to hide UPS Freight options on orders below 150 lbs.
add_filter( ‘woocommerce_package_rates’, ‘show_shipping_method_on_order_weight’, 10, 2 );
function show_shipping_method_on_order_weight( $available_shipping_methods, $package ) {
$order_weight = 0;
foreach( WC()->cart->cart_contents as $key => $values ) {
$product_weight = woocommerce_get_weight($values[ ‘data’ ]->get_weight(),’lbs’);
$quantity = $values[‘quantity’];
if($product_weight && $quantity){
$order_weight = $order_weight + $product_weight*$quantity;
}
}
$weight_oz = $order_weight*16;
if($weight_oz <= 2400){
$shipping_services_to_hide = array(
'wf_shipping_ups:308',
'wf_shipping_ups:14',
);
}else{
$shipping_services_to_hide = array(
'wf_shipping_ups:334',
'wf_shipping_ups:13',
'wf_shipping_ups:01',
'wf_shipping_ups:03',
'wf_shipping_ups:02',
'wf_shipping_ups:12',
);
}
foreach ( $shipping_services_to_hide as &$value ) {
unset( $available_shipping_methods[$value] );
}
return $available_shipping_methods;}
What would the shipping services be for UPS and UPS Freight? These are USPS.