Skip to content

Instantly share code, notes, and snippets.

@rajeshsingh520
Created December 4, 2025 11:43
Show Gist options
  • Select an option

  • Save rajeshsingh520/52322920dcc540865927c218eaef931c to your computer and use it in GitHub Desktop.

Select an option

Save rajeshsingh520/52322920dcc540865927c218eaef931c to your computer and use it in GitHub Desktop.
disable dates by category
add_filter('pisol_dtt_date_sort', function($dates) {
// Define restricted product categories
$restricted_categories = array( 19, 22 );
// Check if products from restricted categories are in the cart
$cart = WC()->cart->get_cart();
$has_restricted_category = false;
if ( $cart ) {
foreach ( $cart as $cart_item ) {
$product_id = $cart_item['product_id'];
$product_cats = wp_get_post_terms( $product_id, 'product_cat', array( 'fields' => 'ids' ) );
if ( array_intersect( $restricted_categories, $product_cats ) ) {
$has_restricted_category = true;
break;
}
}
}
// If restricted products are in cart, filter out restricted dates
if ( $has_restricted_category ) {
$restricted_dates = array( '2025/12/24', '2025/12/25', '2025/12/26', '2025/12/31', '2026/01/01', '2026/01/02' );
$filtered_dates = array();
foreach ( $dates as $date ) {
// Skip if date matches restricted dates
if ( in_array( $date, $restricted_dates ) ) {
continue;
}
// Skip if date falls on Sunday (0 = Sunday in strtotime)
$timestamp = strtotime( str_replace( '/', '-', $date ) );
if ( $timestamp && date( 'w', $timestamp ) == 0 ) {
continue;
}
$filtered_dates[] = $date;
}
return $filtered_dates;
}
return $dates;
}, PHP_INT_MAX, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment