Php 根据星期几禁用特定类别中所有产品的“购买”按钮

Php 根据星期几禁用特定类别中所有产品的“购买”按钮,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在尝试在特定日期停用属于父类别的所有产品的按钮 我尝试了这段代码,但我无法整合条件来设置天数。 我应该根据一周中的天数禁用中的特定类别 add_action('woocommerce_single_product_summary', 'remove_product_description_add_cart_button', 1 ); function remove_product_description_add_cart_button() { // function for deletin

我正在尝试在特定日期停用属于父类别的所有产品的按钮

我尝试了这段代码,但我无法整合条件来设置天数。 我应该根据一周中的天数禁用中的特定类别

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 );
    }
}

使用switch语句,然后定义在哪一天禁用哪些类别

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 );
    }

}

使用switch语句,然后定义在哪一天禁用哪些类别

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 );
    }

}

美好的谢谢美好的谢谢