所以.. 再次重新发布我的问题并减少它以简化和增加焦点之后,在我认为机器人回复结束了我原来的问题之后。
我查看了提出的建议,“你会相信吗”下面的帖子在建议列表中。我以前从未见过。
Increase stock (not decrease) after completed WooCommerce orders?
我必须测试并更改调用,稍微调整代码以适应我的商店模型。
我现在有一种安全可行的方法,只针对报价列表中的股票,并且仅在我发出报价时将股票提升报价列表的数量(数量)。
唯一的缺点是,如果另一个客户出现并看到有库存的佣金,他们可以将其放入他们的篮子,然后它与发出的原始报价不匹配。
“开发另一个时间的代码,以找到一种方法来保留高架和分配的股票”。
我在考虑如何仅触发已发送报价的操作后这样做。
因此,深入研究 Yiths 请求报价代码以找到它更改 WooCommerce 订单状态的类并提出了这个。
感谢@loictheaztec,他对这一灵感负责。
// 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' );
}
}