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 文件中。测试和工作。
对于父产品类别:
允许延期交货并通知客户在 Woocommerce 中的父产品类别
推荐阅读
- javascript - VS Code 自动格式化更漂亮
- python - Python - 如何在 ARIMA 模型中选择某些滞后?
- angular - 无法设置在角度 10 中默认选择的选项
- php - PHP/SQL 错误,意外的变量名
- reactjs - 在不使用 this.state 的情况下从 reactjs 中的数组返回值
- python - 是否可以为 Alembic .py 升级脚本设置模板?
- java - 使用正则表达式,如何忽略给定的字符
- python - 升级pycharm venv python版本
- crystal-reports - Crystal Reports - 检查小写或大写
- javascript - 反应路由耗时太长