Displaying Order Language in WooCommerce Backend Using WPML

In a recent Business Bloomer Club thread, a member asked how to display the language in which an order was placed in the WooCommerce backend, specifically in the order list or single order page.

This feature can be useful for managing orders across multiple languages in a WooCommerce store that uses WPML for multilingual capabilities. Below, we’ll explore ways to retrieve and display the order language, including a solution that leverages order meta fields.

Step 1: Check for Language Meta Data in Orders

WooCommerce typically stores order details in the order’s meta data, which may include information about the language used during checkout if WPML is enabled. By viewing these hidden meta fields, you can confirm if the language data is saved with the order.

Steps to View Hidden Order Meta

  1. Add the Code to Access Hidden Meta Fields: Use a code snippet to reveal hidden meta fields in WooCommerce orders.
  2. Inspect the Meta Data: With the code added, go to a single order page in WooCommerce to view the additional meta information, including any language-related fields.

For example, Rodolfo Melogli suggests using this code to reveal these fields.

Step 2: Add Language Display on WooCommerce Order List

If you identify the key for the language meta (for example, _order_wpml_language), you can then display this information directly on the WooCommerce order list page.

Code Example

Here’s a code snippet to add the order language to the order list in the WooCommerce backend:

add_filter('manage_edit-shop_order_columns', 'add_order_language_column', 20);
function add_order_language_column($columns) {
    $columns['order_language'] = __('Order Language', 'woocommerce');
    return $columns;
}

add_action('manage_shop_order_posts_custom_column', 'show_order_language_column_content');
function show_order_language_column_content($column) {
    global $post;
    if ('order_language' === $column) {
        $language = get_post_meta($post->ID, '_order_wpml_language', true); // Replace with the correct meta key
        echo $language ? strtoupper($language) : __('N/A', 'woocommerce');
    }
}

In this snippet:

  • The new column “Order Language” is added to the WooCommerce order list.
  • The _order_wpml_language meta key retrieves the language; adjust this if the key differs.

Step 3: Display Language on Single Order Page

To make the language visible on the single order page, add the language data to the order details section.

Code Example

add_action('woocommerce_admin_order_data_after_order_details', 'display_order_language_on_single_order');
function display_order_language_on_single_order($order){
    $language = get_post_meta($order->get_id(), '_order_wpml_language', true); // Adjust key if necessary
    if ($language) {
        echo '<p><strong>' . __('Order Language', 'woocommerce') . ':</strong> ' . strtoupper($language) . '</p>';
    }
}

With this approach, the language in which the order was placed is displayed under the order details on the single order page.

Final Thoughts

Displaying the order language in the WooCommerce backend provides a quick reference for multilingual order management. Using WooCommerce’s meta data storage, you can retrieve and display order language information without requiring additional plugins.

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

Your email address will not be published. Required fields are marked *