WooCommerce 增加新订单状态的库存

发布于 2025-01-16 11:00:16 字数 448 浏览 3 评论 0原文

我添加了一个新的订单状态来检查“更改订单”。 我想通过使用此订单状态来增加库存水平,因为客户会将产品寄回给我。它将遵循类似于已取消订单状态的路径,但只有订单状态的名称会是“更改”。当订单状态为“变更”时,将根据订单中的产品数量增加变体产品的库存。

前任: A102-L 库存:12, A108-M 库存: 15.

订单中产品的库存代码和数量: 订单号:1234 订购产品: A102-L-> 1个 A108-M-> 2 件

假设使用这些产品创建了订单。当我将 Woocommerce 订单状态设置为“正在处理”时,它会将 A102-L 的库存水平更新为 11,将 A108-M 的库存水平更新为 13。当我将此订单状态更改为“更改”时,我想将 A102-L 的库存水平更新为 12(11+1),将 A108-M 的库存水平更新为 15(13+2)。

我添加了新的订单状态名称,但无法执行库存增加部分。我该怎么做呢?

I added a new order status to check for "change orders".
I want to increase the stock level by using this order status as the customer will send the product back to me. It will follow a path like the canceled order status, but only the name of the order status will be "change". When the order status is "change", it will increase the stock of the variation product by the quantity of products in the order.

Ex:
A102-L stock: 12,
A108-M stock: 15.

Stock codes and quantities of the products in the order:
Order ID: 1234
order products:
A102-L -> 1 pc
A108-M -> 2 pcs

Suppose an order is created with these products. When I make the Woocommerce order status "processing" it updates the stock levels to 11 for A102-L and 13 for A108-M. When I make this order status "change" , I want to update the stock levels as 12(11+1) for A102-L and 15(13+2) for A108-M.

I added the new order status name but I couldn't do the stock increase part. How can I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清浅ˋ旧时光 2025-01-23 11:00:16
do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );

每当订单状态发生变化时,都会触发此挂钩。

因此,当订单状态更新为“更改”时,可以按如下方式增加订单中商品的库存水平。将代码添加到活动主题functions.php中

add_action('woocommerce_order_status_changed', 'custom_woocommerce_order_status_changed', 10, 4);

function custom_woocommerce_order_status_changed($order_id, $old_status, $new_status, $order) {
        if ('change' == $new_status) {
            wc_increase_stock_levels($order);
        }
    }

    

                 
do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );

This hook is triggered whenever an order status changes.

So to increase stock level of items in an order when the order status updated to 'change' can be done like below. Add the code into active theme functions.php

add_action('woocommerce_order_status_changed', 'custom_woocommerce_order_status_changed', 10, 4);

function custom_woocommerce_order_status_changed($order_id, $old_status, $new_status, $order) {
        if ('change' == $new_status) {
            wc_increase_stock_levels($order);
        }
    }

    

                 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文