php-在Woocommerce中允许缺货并通知客户特定产品类别

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

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

解决方法:

更新

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

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

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

php-在Woocommerce中允许缺货并通知客户特定产品类别

php-在Woocommerce中允许缺货并通知客户特定产品类别

For parent product categories:
07002

上一篇:USACO Stock Market


下一篇:php – 如何在Woocommerce产品变体下拉列表中添加变体库存状态