• Resolved pamuje

    (@pamuje)


    A site migration didn’t go as planned on a woocommerce site and this was uncovered only late. The consequence is that as new users register and place an order, the order history from the user who used the same ID previously (pre-migration) is showing under the new user’s summary of orders (client facing).

    I would like to reassign all orders pre-(migration-date) to (legacy-dummy-user).

    I thought this would do the trick but nothing happens.

    function reassign_orders( ){
    
    if(!is_admin()) return; 
    else {
    $new_customer_id = 286;
    
    // Iterating with a loop through a range of numbers
    for( $order_id = 22680; $order_id <= 22680; $order_id++ ){
    
        // Getting the postmeta customer ID for 'order' post-type
        $customer_id = get_post_meta( $order_id, '_customer_user', true );
    
        // If it's an existing order and doesn't already have this user ID
        // It update the customer ID
        if( !empty($customer_id) && $new_customer_id != $customer_id )
            update_post_meta( $order_id, '_customer_user', $new_customer_id );
    }
    }
    
    }
    
    reassign_orders();

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Reallocate orders to a new user within a date range’ is closed to new replies.