将订单分配给现有客户(在WooCommerce中)

将订单分配给现有客户(在WooCommerce中),woocommerce,Woocommerce,我需要将一些订单分配给另一个客户用户 有没有办法在phpmyadmin中批量完成 订单号范围:23000:24000 目标客户用户id=89 -更新了2-(更正了代码中的一些打字错误) 下面是一个PHP自定义函数,它将执行此任务,使用for循环在订单号范围内进行迭代。它还将使用和功能检查订单中的“客户\用户”met\密钥,并更新该客户ID值 在运行此函数之前,您将执行数据库备份 下面是这个函数的代码: function cristmas_bulk_editing_orders( ){

我需要将一些订单分配给另一个客户用户

有没有办法在phpmyadmin中批量完成

订单号范围:23000:24000

目标客户用户id=89

-更新了2-(更正了代码中的一些打字错误)

下面是一个PHP自定义函数,它将执行此任务,使用for循环在订单号范围内进行迭代。它还将使用和功能检查订单中的
“客户\用户”
met\密钥,并更新该客户ID值

在运行此函数之前,您将执行数据库备份

下面是这个函数的代码:

function cristmas_bulk_editing_orders( ){

    if(!is_admin()) return; // Will work only from Admin Backed.
    else {

        $new_costumer_id = 89;

        // Iterating with a for loop through a range of numbers
        for( $order_id = 23000; $order_id <= 24000; $order_id++ ){

            // Getting the postmeta customer ID for 'order' post-type
            $costumer_id = get_post_meta( $order_id, '_customer_user', true );

            // If it's an existing order and doesn't have already this user ID
            // It update the customer ID
            if( !empty($costumer_id) && $new_costumer_id != $costumer_id )
                update_post_meta( $order_id, '_customer_user', $new_costumer_id );
        }
    }

}

cristmas_bulk_editing_orders();
检查订单是否已按需要更改,并删除所有这些代码


代码已经过测试,可以正常工作。

谢谢您的代码。但当我将此代码添加到function.php时,我在管理页面上看到了一个白色页面。。。问题解决了。您的代码工作得非常好。@LoicTheAztec感谢您提供了非常棒的解决方案。工作很好。。。但我面临的一个问题是,这不适用于客人的订单。。你能帮帮我吗!我还投入了一笔我能负担得起的赏金---@LoicTheAztec我只是喜欢它,但它不是只为一个场景工作。。。为客人定购。。你能帮我吗help@LoicTheAztec我在全新版本的wordpress、woocommerce、新数据库和店面主题上进行了测试。。但是结果是一样的。。所以我认为样品订单的数据并不重要
// cristmas_bulk_editing_orders();