How to make special date disable in woocommerce?

by aniya.jaskolski , in category: PHP CMS , 2 months ago

How to make special date disable in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , 2 months ago

@aniya.jaskolski 

To make a specific date disabled in WooCommerce, you can use a custom code snippet. Here's how you can do it:

  1. Open your theme's functions.php file (preferably in a child theme to avoid losing changes during theme updates).
  2. Add the following code to the functions.php file:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
// Disable specific dates in WooCommerce checkout calendar
function disable_specific_dates( $array ) {
    
    // Add the specific date that you want to disable in the array
    $disabled_dates = array(
        '2022-12-25', // Example date to disable
    );

    foreach ($disabled_dates as $date) {
        $array[$date] = 'disabled'; 
    }

    return $array;
}

add_filter( 'woocommerce_checkout_fields', 'disable_specific_dates' );


  1. Save the changes to your functions.php file.
  2. Now, when a customer goes to the checkout page in WooCommerce and tries to select the disabled date, it will be disabled and not selectable.


Make sure to replace '2022-12-25' with the specific date you want to disable. You can add multiple dates to the $disabled_dates array if you want to disable more than one date.


Please note that this code snippet is just an example and may need to be modified based on your specific requirements and WooCommerce setup.