Skip to content

Instantly share code, notes, and snippets.

@pramodjodhani
Created January 18, 2024 09:08
Show Gist options
  • Save pramodjodhani/b951608fa68deed1450135d5eb293eb8 to your computer and use it in GitHub Desktop.
Save pramodjodhani/b951608fa68deed1450135d5eb293eb8 to your computer and use it in GitHub Desktop.
Iconic WDS - disable timeslot for specific products.
/**
* 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