[英]disable the purchase button for all products in a specific category based on the day 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 );
}
}
使用 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 );
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.