Reputation: 1
I am trying to deactivate the button to all products belonging to a parent categories on specific days.
I tried this code but I can’t integrate the condition to set the days. I should disable specific categories in based on the days of the week
add_action('woocommerce_single_product_summary', 'remove_product_description_add_cart_button', 1 );
function remove_product_description_add_cart_button() { // function for deleting ...
// Set HERE your category ID, slug or name (or an array)
$categories = array('ristorante-5');
//Remove Add to Cart button from product description of product with id 1234
if ( has_term( $categories, 'product_cat', get_the_id() ) ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}
Upvotes: 0
Views: 111
Reputation: 1126
Use a switch statement, then define which categories are diabled on what day.
add_action('woocommerce_single_product_summary', 'remove_product_description_add_cart_button', 1 );
function remove_product_description_add_cart_button() { // function for deleting ...
$disabled_categories = array();
//gets day of week as number(0=sunday,1=monday...,6=sat)
switch ( date('w') ) {
case 0:
$disabled_categories = array('ristorante-5');
break;
case 1:
$disabled_categories = array('ristorante-5');
break;
case 2:
$disabled_categories = array('ristorante-5');
break;
case 3:
$disabled_categories = array('ristorante-5');
break;
case 4:
$disabled_categories = array('ristorante-5');
break;
case 5:
$disabled_categories = array('ristorante-5');
break;
case 6:
$disabled_categories = array('ristorante-5');
break;
}
// Remove Add to Cart button from product description of product with id 1234
if ( has_term( $disabled_categories, 'product_cat', get_the_id() ) ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}
Upvotes: 2