Created
December 20, 2025 01:53
-
-
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
This file contains hidden or 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
| 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