我目前在WooCommerce遇到了一个问题,在客户下订单后,库存库存会立即减少.但是,我想要更改此行为,并实现一个系统,在此系统中,库存数量保持不变,直到我从WooCommerce仪表板手动确认订单.

如果有人能为我提供如何实现这一功能的代码片段或指导,我将不胜感激.我正在寻找一种解决方案,允许我在库存库存减少之前从仪表板确认订单.

推荐答案

您可以做的是,只有在订单状态被store 经理设置为"已完成"时,才允许减少库存盘点,使用以下代码片段:

add_action( 'init', 'custom_wc_maybe_reduce_stock_levels', 10 );
function custom_wc_maybe_reduce_stock_levels(){
    // remove_action( 'woocommerce_order_status_completed', 'wc_maybe_reduce_stock_levels' );

    remove_action( 'woocommerce_payment_complete', 'wc_maybe_reduce_stock_levels' );
    remove_action( 'woocommerce_order_status_processing', 'wc_maybe_reduce_stock_levels' );
    remove_action( 'woocommerce_order_status_on-hold', 'wc_maybe_reduce_stock_levels' );
    
    add_action( 'woocommerce_payment_complete', 'wc_maybe_increase_stock_levels' );
    add_action( 'woocommerce_order_status_processing', 'wc_maybe_increase_stock_levels' );
    add_action( 'woocommerce_order_status_on-hold', 'wc_maybe_increase_stock_levels' );
}

代码放在活动子主题(或活动主题)的函数.php文件中.应该能行得通.

基于WooCommerce的一些核心功能wc_maybe_reduce_stock_levels( $order_id )wc_maybe_increase_stock_levels( $order_id ),涉及管理订单中订单项目的库存水平.

Php相关问答推荐

使用额外的输入字段自定义WooCommerce单个产品

过滤WooCommerce管理员订单列表(+HPOS)中包含其作者产品的订单

在函数内部获取一致的单选按钮值以更新WordPress用户数据

在php中有没有办法比较两个包含相同枚举类型的枚举数组

与会者在WooCommerce中按购物车项目数量自定义 checkout 字段

如何使用这种格式构建XML?

目标类[Set_Locale]不存在.拉威尔

使用与OpenSSL命令行兼容的AES-256-CTR为大型文件创建php代码OpenSSL加密

CKEDITOR-如何在PHP中判断提交后的空数据

如何使用PHP从TXM(XML)标记中读取特定属性

在具有Angular 的 Laravel 应用程序中,不显示图像

如何将不同的 Woocommerce 费用合并为一个名称?

通过添加计数器修改文本区域表单中的重复值

WooCommerce 按产品运输插件:仅收取较高的运输费用

docker |管道失败的 ubuntu 源列表

PHP/Laravel 中的自定义时区

从 laravel 中的日期类型中删除时间

无法在 Laravel 10 中安装 jenssegers/mongodb

如何在光速网络服务器中使用 apache ..htaccess

构建 [Controller] 时目标 [Interface] 不可实例化