首页 > 解决方案 > 订单状态为待付款时如何减少 WooCommerce 可变产品库存?

问题描述

当订单状态为待付款时,我一直在尝试减少 WooCommerce 可变产品的库存数量。默认情况下,当订单状态为待付款时,WooCommerce 不会减少库存。所以我在下面使用了这些代码片段,但它不起作用。根据 WooCommerce 的钩子,它应该可以工作,但不幸的是,事实并非如此。

add_action('init', function() {
    remove_action( 'woocommerce_order_status_pending', 'wc_maybe_increase_stock_levels' );
    add_action( 'woocommerce_order_status_pending', 'wc_maybe_reduce_stock_levels' );
});

或者,

add_action( 'init', 'custom_stock_reduce' );
function custom_stock_reduce() {
    remove_action( 'woocommerce_order_status_pending', 'wc_maybe_increase_stock_levels' );
    add_action( 'woocommerce_order_status_pending', 'wc_maybe_reduce_stock_levels' );
}

你能帮我看看我哪里做错了吗?谢谢你。

标签: wordpresswoocommercehook-woocommerce

解决方案


推荐阅读