Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable shipping checkout fields for WooCommerce booking products

I know that I can automatically disable shipping fields by checking "virtual" on the product submission form - but how could I by default disable shipping fields on the checkout for Woocommerce Booking products (for "booking" product type)?

like image 815
Marko I. Avatar asked Aug 31 '25 22:08

Marko I.


1 Answers

The following will disable checkout shipping fields when a specific product type is in cart (here "booking" product type):

add_filter( 'woocommerce_cart_needs_shipping_address', 'filter_cart_needs_shipping_address_callback' );
function filter_cart_needs_shipping_address_callback( $needs_shipping_address ){
    // Loop through cart items
    foreach ( WC()->cart->get_cart() as $item ) {
        if ( $item['data']->is_type('booking') ) {
            $needs_shipping_address = false;
            break; // Stop the loop
        }
    }
    return $needs_shipping_address;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.


Reminder: to hide “Ship to a different address” in Woocommerce we just use:

add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false');
like image 117
LoicTheAztec Avatar answered Sep 03 '25 12:09

LoicTheAztec