Create product in second language with WPML and Woocommerce Rest API

Viewed 204

I have an issue with creating a translation for a product by WooCommerce Rest API and WPML. the issue is my created translated product did not get linked to the original one. Let's say instead of creating translation for a product it will create a brand new product in default language.

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("translation_of", "354");
urlencoded.append("name", "محصول عربی");
urlencoded.append("lang", "ar");
urlencoded.append("type", "simple");

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://domain.localhost/wp-json/wc/v3/products?consumer_key=ck_key&consumer_secret=cs_secret", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

The result will look like:

enter image description here

But the translated product showed in the product list of default language:

enter image description here

And in the Products list, we have them both side by side :)

enter image description here

What am I missing? Why it isn't translated and instead it creates a new product?

0 Answers
Related