Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
You are trying to capture the language of the customer in WooCommerce orders using WPML, but the meta key 'wpml_language' does not work.
Solution:
The correct meta key to use is 'wpml_languages', which is stored in the 'wp_wc_orders_meta' table. This key reflects the language of the order based on the active user language at the time the order is created on the frontend. Here is how you can retrieve the language from the 'wpml_languages' meta key:

$order = wc_get_order( $order_id );
 
// Retrieve the 'wpml_languages' meta value
$wpml_languages = $order->get_meta( 'wpml_languages' );
 
// If the data is serialized, unserialize it
if ( !empty( $wpml_languages ) ) {
    $languages = unserialize( $wpml_languages );
     
    // Assuming the first entry is the primary language of the order
    $order_language = isset( $languages[0] ) ? $languages[0] : null;
     
    // Output or use the $order_language
    echo 'Order language: ' . $order_language;
}

If this solution does not resolve your issue, or if it seems outdated or irrelevant to your specific case, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please open a new support ticket at WPML support forum.

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.

Tagged: 

This topic contains 1 reply, has 0 voices.

Last updated by Andreas W. 1 week, 2 days ago.

Assisted by: Andreas W..

Author Posts
January 30, 2025 at 3:55 pm #16652713

morenoG-2

Background of the issue:
I am creating a notification system that reports various information about new orders in WooCommerce. I want to capture the language of the customer using WPML. I tried using the meta key 'wpml_language', but it doesn't seem to work.

Symptoms:
The meta key 'wpml_language' does not work for capturing the customer's language in WooCommerce orders.

Questions:
What is the correct meta key used by WPML to capture the language of a customer in WooCommerce orders?

January 30, 2025 at 9:39 pm #16653563

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

The key wpml_language is saved on wp_wc_orders_meta and determines the language of the order.

The source for this value is the active user language when creating on order on Frontend.

Here’s an example of how you could get the language from the wpml_languages meta key:

$order = wc_get_order( $order_id );

// Retrieve the 'wpml_languages' meta value
$wpml_languages = $order->get_meta( 'wpml_languages' );

// If the data is serialized, unserialize it
if ( !empty( $wpml_languages ) ) {
    $languages = unserialize( $wpml_languages );
    
    // Assuming the first entry is the primary language of the order
    $order_language = isset( $languages[0] ) ? $languages[0] : null;
    
    // Output or use the $order_language
    echo 'Order language: ' . $order_language;
}

Best regards
Andreas