On this full full information, I’ll present you the right way to conceal Woocommerce delivery strategies conditionally with none additional plugin. Earlier than you leap in a fast remark although: all of the snippets proven under will go to both to your little one theme’s features.php file or, higher but, use Code Snippets plugin for it.
Video: The right way to Conditionally Cover Woocommerce Transport Strategies
In case you’re not good at including code snippets in your web site, then check out this video.
The right way to disable Woocommerce delivery strategies for a particular delivery class?
Now, there are two stuff you would wish to do beforehand:
- Add a delivery class. Go to Woocommerce >> Settings >> Transport >> Transport lessons and add one. For instance: “Courier solely”
- Write down the delivery class slug as a result of you have to it later. The place to get the slug? See the screenshot under.
- Add delivery class to the wanted product. Open your product and see beneath Transport tab.
Subsequent, go to Snippets >> Add new and paste this snippet right here under inside your code field. Listen although that you might want to change the delivery class slug on line 4 accordingly.
So, if on this instance I’ve a “Courier solely” delivery class with a slug “courier-only”, then substitute the slug within the code accordingly with the proper one.
Yet another factor, on line 12 there’s a delivery technique that you’re hiding (Flat charge). Change the delivery technique title and ID as wanted. The right way to discover your delivery ID quantity? Effectively, check out the video above (see the 3min 44sec mark).
/* Cover WooCommerce delivery technique for a particular delivery class */
operate hide_flat_rate_shipping( $charges, $bundle ) {
// Transport class IDs that want the strategy eliminated
$shipping_classes = array('pakk1'); // Right here goes your delivery class slug
$if_exists = false;
foreach( $bundle['contents'] as $key => $values ) {
if( in_array( $values['data']->get_shipping_class(), $shipping_classes ) )
$if_exists = true;
}
if( $if_exists ) {
unset( $charges['montonio_venipak_courier:4'] ); // Right here goes your delivery technique that must be hidden. Don’t neglect so as to add the proper one right here
}
return $charges;
}
add_filter( 'woocommerce_package_rates', 'hide_flat_rate_shipping', 10, 2 );
If you want to know the right way to conceal Woocommerce a number of delivery strategies utilizing delivery lessons, then see my earlier submit right here.
The right way to Cover Woocommerce Checkout Fields When Native Pickup is Chosen?
One of the annoying issues with the Woocommerce shiping system is that if Native Pickup delivery technique is chosen then you definately nonetheless must fill in all of the tackle and postcode fields. However what when you may mechanically conceal these fields if Native pickup technique is chosen?
.hide_pickup {
show: none !necessary;
}
*/
// Cover Native Pickup delivery technique
add_filter( 'woocommerce_checkout_fields', 'hide_local_pickup_method' );
operate hide_local_pickup_method( $fields_pickup ) {
// change under for the strategy
$shipping_method_pickup ='local_pickup:2';
// change under for the record of fields. Add (or delete) the sector title you need (or don’t need) to make use of
$hide_fields_pickup = array( 'billing_company', 'billing_country', 'billing_postcode', 'billing_address_1', 'billing_address_2' , 'billing_city', 'billing_state');
$chosen_methods_pickup = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping_pickup = $chosen_methods_pickup[0];
foreach($hide_fields_pickup as $field_pickup ) {
if ($chosen_shipping_pickup == $shipping_method_pickup) {
$fields_pickup['billing'][$field_pickup]['required'] = false;
$fields_pickup['billing'][$field_pickup]['class'][] = 'hide_pickup';
}
$fields_pickup['billing'][$field_pickup]['class'][] = 'billing-dynamic_pickup';
}
return $fields_pickup;
}
// Native Pickup – conceal fields
add_action( 'wp_head', 'local_pickup_fields', 999 );
operate local_pickup_fields() {
if (is_checkout()) :
?>