Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 允许延期订单,并通知客户Woocommerce中的特定产品类别_Php_Wordpress_Woocommerce_Product_Stock - Fatal编程技术网

Php 允许延期订单,并通知客户Woocommerce中的特定产品类别

Php 允许延期订单,并通知客户Woocommerce中的特定产品类别,php,wordpress,woocommerce,product,stock,Php,Wordpress,Woocommerce,Product,Stock,在woocommerce中,我试图在functions.php中添加一些代码,以允许针对特定产品类别的缺货。但代码不起作用 如何在Woocommerce中允许缺货并通知客户特定产品类别?已更新 尝试以下操作(您将在阵列中为每个功能设置产品类别): 代码进入活动子主题(或活动主题)的function.php文件。测试和工作 对于母产品类别: 我尝试了function.php中的代码,但出现了一些错误。致命错误:无法在第388行的/home1/digitsor/public\u html/wp

在woocommerce中,我试图在
functions.php
中添加一些代码,以允许针对特定产品类别的缺货。但代码不起作用


如何在Woocommerce中允许缺货并通知客户特定产品类别?

已更新

尝试以下操作(您将在阵列中为每个功能设置产品类别):

代码进入活动子主题(或活动主题)的function.php文件。测试和工作

对于母产品类别:


我尝试了function.php中的代码,但出现了一些错误。致命错误:无法在第388行的/home1/digitsor/public\u html/wp content/themes/dokan/functions.php:369中重新声明filter\u products\u backorders\u allowed()(之前在/home1/digitsor/public\u html/wp content/dokan/functions.php中声明),谢谢您的回复,先生,我已经尝试过了。我将这两个类别放在“允许缺货”和“通知”中,但什么也没有发生。@ErwinManalang我已经添加了一些代码,经过测试,现在它工作得很好……如果它对您有效,请接受答案。谢谢,现在可以用了。我还有最后一个问题,先生,代码似乎只处理子类别。我如何才能在数组中添加根类别或父类别并将类别相乘?对不起,新手的问题。先生,请帮助关于根类别的工作与代码。谢谢,先生
add_filter( 'woocommerce_product_is_in_stock', 'filter_product_is_in_stock', 10, 2 );
function filter_product_is_in_stock( $is_in_stock, $product ){
    // Here set the products categories in the array (can be terms ids, slugs or names)
    $categories = array("clothing");

    if( has_term( $categories, 'product_cat', $product->get_id() ) ){
        $is_in_stock = true;
    }
    return $is_in_stock;
}

add_filter( 'woocommerce_product_backorders_allowed', 'filter_products_backorders_allowed', 10, 3 );
function filter_products_backorders_allowed( $backorder_allowed, $product_id, $product ){
    // Here set the products categories in the array (can be terms ids, slugs or names)
    $categories = array("clothing");

    if( has_term( $categories, 'product_cat', $product_id ) ){
        $backorder_allowed = true;
    }
    return $backorder_allowed;
}

add_filter( 'woocommerce_product_backorders_require_notification', 'filter_product_backorders_require_notification', 10, 2 );
function filter_product_backorders_require_notification( $notify, $product ){
    // Here set the products categories in the array (can be terms ids, slugs or names)
    $categories = array("clothing");

    if( has_term( $categories, 'product_cat', $product->get_id() ) ){
        $notify = true;
    }
    return $notify;
}