Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rajeshsingh520/180715fae88ada3e539a4f419dc28ec4 to your computer and use it in GitHub Desktop.
Save rajeshsingh520/180715fae88ada3e539a4f419dc28ec4 to your computer and use it in GitHub Desktop.
Enable date time plugin for specific category of product only
<?php
add_action( 'wp_loaded', 'pisol_enable_plugin_for_category' );
function pisol_enable_plugin_for_category(){
$enable_for_cat = 107; // this will be your category id for which you want to enable the plugin
$plugin_disabled = true;
if(isset(WC()->cart)){
foreach( WC()->cart->get_cart() as $cart_item ) {
$product_in_cart = $cart_item['product_id'];
if(has_term($enable_for_cat, 'product_cat', $product_in_cart)){
$plugin_disabled = false;
}
}
}
if($plugin_disabled){
add_filter('pisol_disable_dtt_completely',function($var){
return true;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment