Created
January 18, 2024 09:08
-
-
Save pramodjodhani/b951608fa68deed1450135d5eb293eb8 to your computer and use it in GitHub Desktop.
Iconic WDS - disable timeslot for specific products.
This file contains 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
/** | |
* Iconic WDS - disable timeslot for specific products. | |
* | |
* @return bool | |
*/ | |
function iconic_wds_disable_timeslot_for_specific_products( $disabled ) { | |
// todo replace with your product ids. | |
$disable_for_products = array( 10 ); | |
if ( only_these_products_are_in_cart( $disable_for_products ) ) { | |
return false; | |
} | |
return $disabled; | |
} | |
add_filter( 'iconic_wds_delivery_slots_allowed', 'iconic_wds_disable_timeslot_for_specific_products' ); | |
/** | |
* Are only these products in cart. | |
* | |
* @param array $product_ids Product ID. | |
* | |
* @return bool | |
*/ | |
function only_these_products_are_in_cart( $product_ids ) { | |
if ( ! function_exists( 'WC' ) ) { | |
return false; | |
} | |
$cart = WC()->cart->get_cart(); | |
foreach ( $cart as $item ) { | |
if ( ! in_array( $item['product_id'], $product_ids ) ) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment