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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 | - |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Karachi (GMT+05:00)
Tagged: Documentation request
This topic contains 10 replies, has 2 voices.
Last updated by Waqas Bin Hasan 8 months, 1 week ago.
Assisted by: Waqas Bin Hasan.
Author | Posts |
---|---|
March 12, 2024 at 4:04 pm #15400634 | |
newcomS |
Tell us what you are trying to do? Is there any documentation that you are following? Is there a similar example that we can see? What is the link to your site? |
March 12, 2024 at 5:48 pm #15401002 | |
Waqas Bin Hasan Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Hi, Thank you for contacting the support. I'll recommend checking the following guides: - https://wpml.org/documentation/related-projects/woocommerce-multilingual/using-wordpress-rest-api-woocommerce-multilingual/ As well as, updating WordPress to the latest version, so you get latest features and bug fixes. Remember to take full backup of site and database before updating! Regards. |
March 15, 2024 at 1:04 pm #15414548 | |
newcomS |
Hi Waqas Thank you for your response. In the meantime we figured out how to create the attributes, but what we're still trying to do, is create the attribute term in the respective language. Can you help us out with that? Thanks and Best Regards, |
March 15, 2024 at 5:38 pm #15415632 | |
Waqas Bin Hasan Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Have you checked "Creating Taxonomy Terms (Product Category, Tag, Attribute, Shipping Class)" section and then at the bottom an example about "Translate Global Attribute Term" like: $attribute_term = [ 'name' => 'Black ES', 'translation_of' => $original_attribute_term_id, 'lang' => 'es' ]; $woocommerce->post( 'products/attributes/{$attribute_id}/terms', $attribute_term );
|
March 18, 2024 at 8:33 am #15419518 | |
newcomS |
We add the Attribute Terms when creating the Product and inside the Product there's an Array with Attributes that looks like the one in the Screenshot. the "id" parameter is the Attribute assigned to the value and inside the "options" array there's the attribute. Is it correct, that we have to add the "lang" parameter to the "options" array to achieve the same solution? |
March 18, 2024 at 12:37 pm #15420880 | |
newcomS |
Following your Reference to the Documentation, we managed to create the attribute terms in the respective languages (german, french, english). But when we try to assign the term to the product via slug, it either doesn't assign it or it creates a new term. $data = [ This is the reference we're using to create the products just without the the 'translation_of' parameter because we don't want the products to be linked. |
March 18, 2024 at 4:28 pm #15422547 | |
Waqas Bin Hasan Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Thank you for the details, I'll try to consult with my team about it. But before moving to that, can you please explain about:
Aren't you trying to create product attributes in a specific language? And why won't want to link to the product? |
March 19, 2024 at 7:31 am #15424219 | |
newcomS |
We want to create products with their attributes in different languages, but without the 'translation_of' parameter. That is all. We need to create the attribute terms in the specific language, so we can use our filter plugin for the products and to display them via grid. as of now, the filter can not see the attribute terms because they are all in the main language german. thanks for your help. |
March 19, 2024 at 9:26 pm #15428923 | |
Waqas Bin Hasan Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Thank you for the updates. I discussed the matter with my team and they'd like to know about the following scenarios: 1. Create a product in a second language with a term that already exists in the second language. 2. Create a product in a second language with a term that does NOT already exist in the second language. 3. Create a product that is a translation of an existing product with a term that already exists in the second language. 4. It'll also be helpful to know if it works with "translation_of" too. 5. Does $global_attribute_id have a correct value? Maybe comparing these steps will help figure out where/if things are going wrong. Based on your findings, I'll be able to get more help. |
March 20, 2024 at 4:22 pm #15433020 | |
newcomS |
During Testing i have encountered another issue. I create the attribute Term like following: after that it gives me the error: Missing Parameter: name [rest_missing_callback_param] After the POST call for creating the Attribute, i have tried adding the new term to the Product by slug and by term_id. And to answer your Question 5: yes, global_attribute_id is correct. |
March 20, 2024 at 10:34 pm #15433922 | |
Waqas Bin Hasan Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Thank you for the updates. Did you get a chance to check other scenarios? And can you share your findings please? I got some additional info from the team and they confirmed these working. I am sharing some code below from their tests, which may be relevant and be of your interest: /** * Create Global Attribute */ $a = false; $data3 = [ 'name' => 'Color', 'slug' => 'pa_color', 'type' => 'select', 'order_by' => 'menu_order', 'has_archives' => true ]; try { $a = $wc->post( 'products/attributes', $data3 ); } catch ( Exception $e ) { echo "Error:\n"; print_r( $e->getMessage() ); } if ( $a !== false ) { echo "Success:\n"; echo '<pre>'; print_r( $a ); echo '</pre>'; } /** * Create Global Terms */ $b = false; $data4 = [ 'create' => [ [ 'name' => 'Blue-en', 'lang' => 'en' ], [ 'name' => 'Red-en', 'lang' => 'en' ] ] ]; try { $b = $wc->post( 'products/attributes/' . $a->id . '/terms/batch', $data4 ); } catch ( Exception $e ) { echo "Error:\n"; print_r( $e->getMessage() ); } if ( $a !== false ) { echo "Success:\n"; echo '<pre>'; print_r( $b ); echo '</pre>'; } /** * Create Variable Product with Global Attribute */ $r = false; $data = [ 'name' => 'Test Variable Product', 'type' => 'variable', 'description' => 'Test Variable Product for REST', 'lang' => 'en', 'translation_of' => null, 'attributes' => [ [ 'id' => $a->id, 'visible' => true, 'variation' => true, 'options' => [ 'Blue-en', 'Red-en' ] ] ] ]; try { $r = $wc->post( 'products', $data ); } catch ( Exception $e ) { echo "Error:\n"; print_r( $e->getMessage() ); } if ( $r !== false ) { echo "Success:\n"; echo '<pre>'; print_r( $r ); echo '</pre>'; } /** * Create Product Variation */ $y = false; $data2 = [ 'create' => [ [ 'lang' => 'en', 'translation_of' => null, 'regular_price' => '10', 'attributes' => [ [ 'id' => $a->id, 'option' => 'blue-en' ] ] ], [ 'lang' => 'en', 'translation_of' => null, 'regular_price' => '10', 'attributes' => [ [ 'id' => $a->id, 'option' => 'red-en' ] ] ] ], ]; try { $y = $wc->post( 'products/' . $r->id . '/variations/batch', $data2 ); } catch ( Exception $h ) { echo "Error:\n"; print_r( $h->getMessage() ); } if ( $y !== false ) { echo "Success:\n"; echo '<pre>'; print_r( $y ); echo '</pre>'; } One thing that might interest you, is the use of 'translation_of' => null. Since you don't want to use this param then perhaps set it to null instead of omitting it altogether? |
The topic ‘[Closed] Creating Product Attributes in different languages’ is closed to new replies.