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: Documentation request
This topic contains 7 replies, has 3 voices.
Last updated by Thomas Henninger 1 year, 10 months ago.
Assisted by: Christopher Amirian.
Author | Posts |
---|---|
January 20, 2023 at 5:35 pm #12861823 | |
Thomas Henninger |
Hello, We try to get the Order language for our WooCommerce Shop with this code: $order_lang = get_post_meta($order_id, 'wpml_language', true); It gives a "0" as a result. We are using this code in functions php after the order is placed: // SENDINBLUE EVENT NEW ORDER HOOK // Wenn Upseller bestellt wurde - dann setze Cookie damit das nicht nochmal kommt if(!isset($_COOKIE['upselling_starter_buyed'])) { foreach ( $items as $item ) { if ($product_id == 17328 || $product_id == 22563 || $product_id == 26000 || $product_id == 25976 || $product_id == 24950 || $product_id == 24965) { if (isset($order_id) && $order_id) { $order = wc_get_order($order_id); $order_lang = get_post_meta($order_id, 'wpml_language', true); foreach ($order->get_items() as $item) { $order_ids_list = implode( ',', $item_sku ); $url = 'hidden link'; $data = array( $options = array( $context = stream_context_create($options); |
January 23, 2023 at 10:35 am #12871481 | |
Thomas Henninger |
Hello, To keep it simple: This function retuns "0" for an new Order, but it should return the lang code: get_post_meta($order_id, 'wpml_language', true); - WooCommerce Multilingual & Multi-Currency is updated and installed What can we do? Thanks! |
January 23, 2023 at 11:56 am #12872347 | |
Dražen Duvnjak Supporter
Languages: English (English ) Timezone: Europe/Zagreb (GMT+01:00) |
Hello, thanks for contacting us. The mentioned code should work, I would suggest checking if the code work on a simple environment, WP default theme and only WPML plugins and WooCommerce, to confirm nothing else is causing it. Also please try to see if the issue happens for the default language or translated. Since in your code, I see you are using products ID, so it could be you are getting the order language from the default language product ID, but actually, order was made in 2nd language, so a different ID: If the issue still happens let us know and we will provide a new test site, where you can try to show us the issue so it can be ecalated for further check. Thanks, |
January 24, 2023 at 9:09 am #12878589 | |
Thomas Henninger |
Hello, Just for understanding: I want to get the Langauge of an ORDER not of the products in the Order. I have read, that there is the possibility with WooCommerce Multilingual (WCML) to change the Order langauge manually - but i cannot find this in the edit order place (WooCommerce > Order , Edit). Am I wrong with this or is there something missing? |
January 25, 2023 at 7:18 am #12886433 | |
Christopher Amirian Supporter
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Hi there, You are correct to assume that the order itself does not have a language. Even if you go to WordPress Dashboard > Woocommerce > Orders you will see that the top admin language bar goes away. Because there is no meta data assigned to Order to have a separate language. Woocommerce Orders do not have a language. So the order language will always be `nothing`. But the products inside the order or the checkout page have language and you can use that information to do whatever you want to do in your code. If you want to send an email in a specific language please make sure the email is translated: Also check the custom-coded email translation section of the documentation above. Also, you might find the documentation below helpful: https://wpml.org/documentation/support/sending-emails-with-wpml/ Thank you. |
January 26, 2023 at 10:03 am #12895985 | |
Thomas Henninger |
Hello Christopher, Thank you for your information! What I need is the language of a product from the cart. Is this the correct code for this to do? : $lang = get_post_meta(25868, 'wpml_language', true); I want use this in functions.php within a little loop: foreach( $cart->get_cart() as $cart_item ) { ... The function says that the first value / variable should be a post_id for this function: get_post_meta(post_id, 'wpml_language', true); But I want to use this for a product, so is there something else to do to get the correct langauge from this? Thanks! |
January 27, 2023 at 10:14 am #12903055 | |
Christopher Amirian Supporter
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Hi there, All that WPML can offer you can see here in the Hooks list: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/ One that I have in mind is this: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#hook-605256 So basically it gives you the ID of the other language or the ID of the current language. It does not matter if it is a post or product as the product is also a custom post type. If you want to know the language code you can try this: https://wpml.org/wpml-hook/wpml_element_language_code/ But in general try to check the other hooks and you might find the one that is suitable for your needs. Thanks. |
January 27, 2023 at 11:02 am #12903335 | |
Thomas Henninger |
Hello! I tried some other work-arround with this issue via jquery and it gave good results. Thanks for the information! |