phpmysqlsqlwordpresswoocommerce

Change Orders Currency in WooCommerce via a SQL query


I don't have anything to start with, only that I'm stuck. I migrated an Ecwid Store to Woocommerce via an external Service (talked with their support for hours and they deny it's their fault).

Let's cut to the chase, the Store currency of the Original Store and the new is Euro (no Multi-currency enabled), but all imported Orders are shown in USD and it says the order was made in USD, is there a way to change all past orders to Euro via MySql or via a function, I searched for a long time and all I found was concerning orders to be made or Problems mit Multi-currency. Changing the Order Currency is vital because of the external Software used for Taxes.

Any help would be much appreciated


Solution

  • With WordPress class WPDB will allow you to run a simple SQL query to change all related orders currency from "USD" to "EUR".

    Always make a database backup before.

    Paste this code in function.php file of your active child theme (or active theme):

    // Simple SQL query in a function
    function change_orders_currency_from_usd_to_eur(){
        global $wpdb;
    
        $wpdb->query( "
            UPDATE {$wpdb->prefix}postmeta
            SET meta_value = 'EUR'
            WHERE meta_key = '_order_currency'
            AND meta_value = 'USD'
        " );
    }
    // Run the function
    change_orders_currency_from_usd_to_eur();
    

    You will use and run the code below once, browsing any page of your web site.


    Or you can run this SQL query directly from phpMyAdmin:

    UPDATE wp_postmeta
    SET meta_value = 'EUR'
    WHERE meta_key = '_order_currency'
    AND meta_value = 'USD'
    

    Bothe are tested and work.