This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 3 replies, has 2 voices.

Last updated by Bruno Kos 1 month, 2 weeks ago.

Assigned support staff: Bruno Kos.

Author Posts
August 27, 2019 at 10:17 am #4464993

manuelC-26

We have a custom made plugin that exports orders from our WooCommerce into our ERP.

After installation of WPML we are getting the wrong variation ID for the product to export.
We have an order for product variation 44966 (which is the Portuguese variation) but on exporting, we're getting variation 72370, which is the English version.

Our code uses the WooCommerce API and was working correctly before. A sample snippet, where $order is a WC_Order instance.

    $items = $order->get_items();
    foreach ($items as $item) {
        $product = $item->get_product();
        $variation_id = $item->get_variation_id();   // <-- This is were the problem happens
    }

I'm guessing that this is somehow related to the language of my backoffice user, since the export runs OK on the command line (using wp-cli) with the exact same code.

August 27, 2019 at 12:32 pm #4466559

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

I tested some things and checked this scenario on a clean installation.

In the woocommerce backoffice, both orders show the same variation ID which is the older Portuguese one...

This is normal behaviour, as I have been told by our 2nd tier support (mostly because we don't filter orders, them not being translatable and products inherit most values from originals).

Can you tell me this:

On the database, the portuguese order has the portuguese ID and the english order has the english ID.

The code above you posted (in the initial reply) - how does it work for that latest order now? Does it return the correct value? If yes, it would mean that these values entered database wrong for some reason and we cannot know why, unless we have a clear way to reproduce this issue.

Regards,
Bruno Kos

August 27, 2019 at 1:05 pm #4466979

manuelC-26

Hi Bruno,

I've tried exporting again with our custom plugin and everthing is OK. The portuguese order is exporting the Portuguese product and the English order is exporting the English product.
So this seems to have been a mistake on our end that were expecting a Portuguese product to be exported when the order was for an English one. This was driven by the WooCommerce backoffice that is always showing the Portuguese variation even when the product seems to be the English one (as per the screenshot I sent during our chat).

Any way to show the correct ordered variation in the backoffice?

Kind regards,
Manuel

August 27, 2019 at 1:32 pm #4467271

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

You can do this like this:
Users -> Your Profile -> Check "Set admin language as editing language." option

Now open Dashboard and open orders, you will see a different ID now (of the product ID of the language in which it was ordered).

Regards,
Bruno Kos