Created
September 3, 2025 06:16
-
-
Save pramodjodhani/7faaf34662808c52263ffb4763e9d7f1 to your computer and use it in GitHub Desktop.
WDS - Disable Monday (weekday) for given product in cart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Modify allowed days based on cart items. | |
* | |
* @param array $allowed_days | |
* @param bool $minmax | |
* * @return mixed | |
*/ | |
function iconic_wds_modify_allowed_days( $allowed_days, $minmax ) { | |
if ( $minmax ) { | |
return $allowed_days; | |
} | |
// Check if any food items are in the cart. | |
// @todo modify product ids. | |
$in_cart = iconic_check_for_cart_item_in_cart( array( 150 ) ); | |
// If no, return normal settings. | |
if ( ! $in_cart ) { | |
return $allowed_days; | |
} | |
// disable monday | |
$allowed_days[1] = false; | |
return $allowed_days; | |
} | |
add_filter( 'iconic_wds_allowed_days', 'iconic_wds_modify_allowed_days', 10, 2 ); | |
/** | |
* Check cart for product in category. | |
* | |
* @param array $categories Categories. | |
* | |
* @return bool | |
*/ | |
function iconic_check_for_cart_item_in_cart( $product_ids = array() ) { | |
if ( empty( $product_ids ) || empty( WC()->cart ) ) { | |
return false; | |
} | |
// Set our flag to be false until we find a product with matching ID. | |
$has_item = false; | |
// Loop through cart items to check for matching product IDs. | |
foreach ( WC()->cart->get_cart() as $cart_item ) { | |
$product_id = $cart_item['product_id']; | |
if ( in_array( $product_id, $product_ids ) ) { | |
$has_item = true; | |
break; | |
} | |
} | |
return $has_item; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment