【问题标题】:WooCommerce increase stock button on order pageWooCommerce 在订单页面上增加库存按钮
【发布时间】:2021-11-03 12:41:32
【问题描述】:

是否有人拥有(或知道)PHP 代码 sn-p 解决方案来添加自动化,例如通过报价列表增加库存或在订单页面中恢复原始增加库存按钮的复选框;在发出报价之前?

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

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

提前致谢。

【问题讨论】:

标签: php button woocommerce orders stock


【解决方案1】:

所以.. 再次重新发布我的问题并减少它以简化和增加焦点之后,在我认为机器人回复结束了我原来的问题之后。

我查看了提出的建议,“你会相信吗”下面的帖子在建议列表中。我以前从未见过。

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' );
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-24
    • 2020-12-20
    • 2021-10-16
    • 2018-05-16
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 1970-01-01
    相关资源
    最近更新 更多