跳到内容 跳到侧边栏

標籤: 

本主题包含 0 則回覆 ,有 0 voices 。

最后由 dimitrisD-7 6 days, 14 hours前 更新。

协助者:: Dražen.

作者 帖子
2 10 月, 2025 于 7:29 上午 #17450645

dimitrisD-7

Background of the issue:
I am trying to update products using a custom plugin. We are using a standard method to update the product, but every few days an issue on some products comes up, and it doesn't let us edit the original version of the product with the primary language nor the translated one. I found something online and wanted to check if that would fix the problem. We have the product_id for every product, and I wanted to ask if this code is ok to use in order to set the language of the products properly: global $sitepress; if (function_exists('wpml_update_element_language_details')) { $element_type = 'post_product'; $trid = $sitepress->get_element_trid($product_id, $element_type); wpml_update_element_language_details([ 'element_id' => $product_id, 'element_type' => $element_type, 'trid' => $trid, 'language_code' => $lang, 'source_language_code' => ($lang === PRIMARY_LANG) ? null : PRIMARY_LANG, ]);

Symptoms:
Every few days, an issue arises on some products that prevents editing the original version of the product in the primary language and the translated one.

Questions:
Is the code provided correct to set the language of the products properly?
Will the code fix the issue of not being able to edit the original and translated versions of the product?