Answer a question

I need to create a hook to get and print the customer language in the admin order page details. I mean the language the customer selected in the site to process his order.

UPDATE: I use WPML for languages.

The closest I fount is this post but I can not see how it can help me: Get Woocommerce customer order language

I just to print the value somewhere in the Admin order page details.

I guess that the code should be something like:

function add_language(){  
// get language for the order
// print language in Order Admin page

 }
add_action( 'woocommerce_admin_order_data_after_order_details', 'add_language' );

Answers

I have not tested this because I am not using the plugin but according to the information I have found. The postmeta table contains a meta_key wpml_language

function action_woocommerce_admin_order_data_after_order_details( $order ) {
    // Get ID
    $order_id = $order->get_id();
    
    $wpml_language = get_post_meta( $order_id, 'wpml_language', true );
    
    if ( ! empty ( $wpml_language ) ) {
        echo 'lang = ' . $wpml_language;
    } else {
        echo 'not found!';
    }
}
add_action( 'woocommerce_admin_order_data_after_order_details', 'action_woocommerce_admin_order_data_after_order_details', 10, 1 );
Logo

WooCommerce社区为您提供最前沿的新闻资讯和知识内容

更多推荐