Woocommerce 自动将订单分配给不同的商店经理

问题描述 投票:0回答:1

我们目前经营一家店,有2名店长,基于公平,我希望他们能够基本上接待相同数量的顾客并处理订单。

我目前的想法是检查订单的账单电话号码的最后一位,如果是基数(1,3,5,7,9),则将其分配给第一个店长。

或者是偶数(2,4,6,8,0)就会分配给第二个店长

如果这很难实现,那么可以通过订单号的最后一位来实现吗?

有什么建议吗? 谢谢!

从此链接如何将订单分配给 Woocommerce 中的某个商店经理

我发现这个代码是类似的,但是按国家分配不适合我的商店

function before_checkout_create_order($order, $data) {

        $country = $order->billing_country;
        $store_manager_id = '';

        $belgium_region = ['BE', 'NL', 'DE'];
        $czech_region = ['CZ', 'AT', 'SI', 'HU'];
        $uk_region = ['GB'];

        if (in_array($country, $belgium_region)) {
            // Manually assigning the _store_manager_id using the user id, yours will differ
            $store_manager_id = 7;
        } else if (in_array($country, $czech_region)) {
            $store_manager_id = 3;
        } else if (in_array($country, $uk_region)) {
            $store_manager_id = 2;
        } else {
            $store_manager_id = 1;
        }

        $order->update_meta_data('_store_manager_id', $store_manager_id);
    }
    add_action('woocommerce_checkout_create_order', 'before_checkout_create_order', 20, 2);
php wordpress woocommerce orders userid
1个回答
0
投票

尝试以下操作,通过将其用户 ID 添加为自定义元数据,将两个商店经理之一分配给当前订单(代码已注释)

add_action('woocommerce_checkout_create_order', 'assign_order_to_shop_manager');
function assign_order_to_shop_manager( $order ) {
    // Define the shop manager user IDs below
    $shop_manager_user_id1 = 12;
    $shop_manager_user_id2 = 18;

    // Get the last (previous) order assigned User (from options custom field)
    $assigned_to = (int) get_option('last_order_assigned_user_id'); 

    // Check the previous assigned shop manager to switch to the other shop manager for this order
    if ( $assigned_to === $shop_manager_user_id1 ) {
        $assigned_to = $shop_manager_user_id2;
    } else {
        $assigned_to = $shop_manager_user_id1;
    }
    // Assign this order to one of the shop managers user Id (alternatively)
    $order->update_meta_data('_shop_manager_user_id', $assigned_to);

    // Update the assigned shop manager as the last order assigned (to options custom field)
    update_option('last_order_assigned_user_id', $assigned_to);
}

代码位于子主题的functions.php 文件中(或插件中)。应该可以。

© www.soinside.com 2019 - 2024. All rights reserved.