【问题标题】:Auto-complete Paid Orders only for specific product IDs on Woocommerce仅针对 Woocommerce 上的特定产品 ID 自动完成付费订单
【发布时间】:2019-08-06 14:57:03
【问题描述】:

有什么方法可以在 Woocommerce 上仅针对特定产品 ID 自动完成订单?

我使用代码on this thread 自动完成订单。

我还阅读了this thread,但它从自动完成中排除了产品 ID。而且我无法让它反过来工作。

由于我的商店中有 20 多种产品,而我只想在其中 2 种产品上使用自动完成功能,如果我可以指定要自动完成的订单 ID,那就太好了。

【问题讨论】:

    标签: woocommerce


    【解决方案1】:

    这是一种自动完成特定产品 IDS 的已付款订单的方法:

    add_action( 'woocommerce_payment_complete_order_status', 'wc_auto_complete_paid_order', 10, 3 );
    function wc_auto_complete_paid_order( $status, $order_id, $order ) {
        // Below the targeted product Ids
        $targeted_ids = array(37, 53);
    
        // Loop through order line items
        foreach( $order->get_items() as $item ) { 
            if ( in_array( $item->get_product_id(), $targeted_ids ) || in_array( $item->get_variation_id(), $targeted_ids ) ) {
                return 'completed';
            }
        }
    
        return $status;
    }
    

    代码进入活动子主题(或活动主题)的functions.php文件中。


    【讨论】:

    • 我想知道的另一件事是,如果我通过在购物车中添加 1 个自动完成产品和 1 个非自动完成产品结帐,它仍然在付款后将其标记为完成。在这种情况下,我有什么办法可以将其标记为处理?非常感谢您的回复。
    猜你喜欢
    • 2019-01-19
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    • 2023-01-25
    • 1970-01-01
    • 2020-03-15
    • 2021-04-25
    • 2019-10-09
    相关资源
    最近更新 更多