本文介绍了允许缺货并通知客户 Woocommerce 中的特定产品类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 woocommerce 中,我正在尝试在 functions.php
中添加一些代码以允许特定产品类别的延期交货.但是代码不起作用.
IN woocommerce I'm trying to add some code in functions.php
to allow backorder for specific product categories. But the code doesn't works.
如何允许缺货并通知客户 Woocommerce 中的特定产品类别?
How can I allow backorders and notify customer for specific product categories in 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 文件中.经测试有效.
Code goes in function.php file of your active child theme (or active theme). Tested and works.
对于父产品类别:
在 Woocommerce 中允许缺货并通知客户父产品类别
这篇关于允许缺货并通知客户 Woocommerce 中的特定产品类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!