WooCommerce 增加订单页面上的库存按钮

WooCommerce increase stock button on order page

有没有人有(或知道)PHP 代码片段解决方案来添加自动化,比如一个复选框以按报价列表增加库存或恢复订单页面中的原始增加库存按钮;在发出报价之前 ?

我已经搜索了很多天和几个小时来寻找代码解决方案或插件 => 没有。

我相信 WooCommerce 曾经在订单页面上有这个按钮,但现在没有了,我在 Woo5.6.0、WP5.8 和 PHP7.4

提前致谢。

所以.. 在重新 post 我的问题并减少它以简化和增加焦点之后,在我认为机器人响应关闭了我原来的问题之后。

我查看了出现的建议,“你会相信吗”下面的 post 在建议列表中。我以前没见过这个。

我必须测试并更改调用,稍微调整代码以适应我的商店模型..

我现在有一种安全的工作方式,可以仅针对报价列表中的股票,并且在发送报价时仅按报价列表金额(数量)提升股票。

唯一的缺点是,如果另一个客户出现并看到库存中的佣金,他们可以将其放入购物篮,然后它与发出的原始报价不符。

“下次再开发代码以找到一种方法来保留已提升和分配的库存”。

我是在考虑如何只对已发送的报价触发操作后才这样做的。

所以深入了解 Yiths 请求报价代码以找到 class 它改变了 WooCommerce 订单状态并提出了这个。

感谢@loictheaztec,他对这个灵感负责。

<pre><code>// Increase stock on pending quote order status - An experiment "ywraq-pending" add_action( 'woocommerce_order_status_ywraq-pending', 'action_on_quote_sent' , 10, 1 ); function action_on_quote_sent( $order_id ) { // Get an instance of the order object $order = wc_get_order( $order_id ); // Iterating though each order items foreach ( $order->get_items() as $item_id => $item_values ) { // Item quantity $item_qty = $item_values['qty']; // getting the product ID (Simple and variable products) $product_id = $item_values['variation_id']; if( $product_id == 0 || empty($product_id) ) $product_id = $item_values['product_id']; // Get an instance of the product object $product = wc_get_product( $product_id ); // Get the stock quantity of the product $product_stock = $product->get_stock_quantity(); // Increase back the stock quantity wc_update_product_stock( $product, $item_qty, 'increase' ); } }