Skip to content

Instantly share code, notes, and snippets.

@rajeshsingh520
Created December 20, 2025 01:53
Show Gist options
  • Select an option

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

Select an option

Save rajeshsingh520/d3c957beebcdd056149f62050b39ca14 to your computer and use it in GitHub Desktop.
disable date and time options when cart only contain product from specific category
class pisol_marp_disable_dtt_plugin_options_for_category{
public $disable_for_cat = array(19, 23);
function __construct(){
add_filter('pisol_disable_dtt_completely', array($this, 'disableDateTimePlugin'));
}
function disableDateTimePlugin($value){
if(is_admin()) return;
$has_restricted_product = false;
$has_other_product = false;
if(isset(WC()->cart)){
foreach( WC()->cart->get_cart() as $cart_item ) {
$product_in_cart = $cart_item['product_id'];
if(has_term($this->disable_for_cat, 'product_cat', $product_in_cart)){
$has_restricted_product = true;
} else {
$has_other_product = true;
}
}
}
if($has_restricted_product && !$has_other_product){
return true;
}
return false;
}
}
add_action('wp_loaded', function(){
new pisol_marp_disable_dtt_plugin_options_for_category();
}, 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment