Skip to content

Instantly share code, notes, and snippets.

@pramodjodhani
Last active September 18, 2025 07:10
Show Gist options
  • Save pramodjodhani/4e6892b0b40489aaee720efec385913d to your computer and use it in GitHub Desktop.
Save pramodjodhani/4e6892b0b40489aaee720efec385913d to your computer and use it in GitHub Desktop.
WDS - disable certain timeslot for specific products
<?php
/**
* Iconic WDS: Disable timeslots for products in cart.
*/
function iconic_wds_disable_timeslots_for_products( $timeslots ) {
// These timeslots will be disabled for the given product IDs.
// How to get the timeslot ID: https://www.loom.com/share/96bd5674116e416e933eb932742adf7b
// Todo - update this map with the actual timeslots and products.
$disable_timeslots_product_map = array(
// Example: timeslot_id => [product_id1, product_id2, ...]
'68a6b8b3d2890' => array(
120
),
);
$timeslots_to_disable = array();
foreach ( $disable_timeslots_product_map as $timeslot_id => $product_ids ) {
if ( iconic_wds_are_products_in_cart( $product_ids ) ) {
$timeslots_to_disable[] = $timeslot_id;
}
}
foreach ( $timeslots_to_disable as $timeslot_id ) {
foreach ( $timeslots as $key => $timeslot ) {
if ( str_contains( $timeslot_id, $timeslot['id'] ) ) {
unset( $timeslots[ $key ] );
}
}
}
return $timeslots;
}
add_filter( 'iconic_wds_timeslots', 'iconic_wds_disable_timeslots_for_products' );
function iconic_wds_are_products_in_cart( $product_ids ) {
if ( ! function_exists( 'WC' ) || ! WC()->cart ) {
return false;
}
if ( empty( $product_ids ) ) {
return false;
}
$cart = WC()->cart->get_cart();
if ( empty( $cart ) ) {
return false;
}
foreach ( (array) $product_ids as $product_id ) {
foreach ( $cart as $cart_item ) {
$product = isset( $cart_item['data'] ) ? $cart_item['data'] : null;
$in_cart_ids = array(
isset( $cart_item['product_id'] ) ? (int) $cart_item['product_id'] : 0,
isset( $cart_item['variation_id'] ) ? (int) $cart_item['variation_id'] : 0,
( $product && method_exists( $product, 'get_parent_id' ) ) ? (int) $product->get_parent_id() : 0,
);
if ( in_array( (int) $product_id, $in_cart_ids, true ) ) {
return true; // any match is enough
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment