Skip to content Skip to sidebar

This thread is resolved. Here is a description of the problem and solution.

Problem:
In a WooCommerce environment using WPML and WooCommerce Multilingual (WCML), the _product_image_gallery meta is stored correctly per language in the database. However, on the frontend, the gallery IDs returned by WordPress functions like get_post_meta() and $product->get_gallery_image_ids() differ from the database values. This discrepancy causes the frontend gallery to display incorrect images.

Solution:
The issue arises due to the WCML_Product_Gallery_Filter::localize_image_ids filter, which modifies the _product_image_gallery during metadata retrieval. To resolve this, the client provided a custom workaround that was valid for their site, but might not be valid on other sites.

Please note that this solution might become outdated or may not apply to your specific case. If this solution does not resolve your issue, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket.

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.

This topic contains 18 replies, has 0 voices.

Last updated by Paola Mendiburu 1 month, 1 week ago.

Assisted by: Paola Mendiburu.

Author Posts
March 3, 2026 at 1:42 pm #17868724

ondrejd-2

Thank you for the clear answer.

We understand that this will not be prioritized for development.

In that case, we would like to shift the discussion toward building a custom solution on our side.

However, to do that properly, we need technical clarification from your side, since WPML/WCML internal handling of media and language relationships is not sufficiently documented for advanced use cases.

Specifically, we need guidance on:

1. How Media Translation internally links original attachments to translated attachments (database structure and relevant tables).
2. Which hooks or filters are triggered when assigning a translated image via the Media Translation screen.
3. Whether there is a recommended internal function for programmatically connecting an existing attachment in one language as the translation of another attachment.
4. Whether there are internal APIs used by Media Translation that are safe to rely on in custom development.

We are not asking you to write custom code for us.

We are asking for architectural clarification so that we can implement a stable workaround without breaking WPML compatibility or future updates.

Given that we are long-term paying customers operating a production WooCommerce environment, access to proper technical guidance is essential.

We would appreciate concrete technical answers to the above points so we can proceed independently.

March 4, 2026 at 3:26 pm #17872437

Paola Mendiburu
WPML Supporter since 11/2020

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Madrid (GMT+02:00)

Hi there!

I have asked our developers and I will let you know when I have more info.

March 10, 2026 at 2:27 pm #17885929

ondrejd-2

Hi,

I just wanted to follow up regarding this.

On the 4th you mentioned that you had asked the developers and would update me once you had more information. Since I haven’t seen an update yet, I wanted to check whether there has been any response from the development team.

If possible, please let me know the current status of the request or whether there is anything further needed from our side.

Thanks in advance.

March 11, 2026 at 9:59 am #17888073

Paola Mendiburu
WPML Supporter since 11/2020

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Madrid (GMT+02:00)

Hi there!

I have got an answer from our developers:

There is no public API specifically related to this, the client will have to get their hands dirty implementing a workaround.

This is the key information they need to know with respect to what happens when you use Media Translation to show different images for different languages.

Let's say you have English as a default language and Spanish as a second language.

Your Media Library has a picture of a cat, and let's assume that this cat picture has been duplicated to Spanish as well. (Prior to WPML 4.8 this happened automatically; now the duplicates are only created if and when needed, which depends on what is being used for a page builder.)

Let's say that you want the cat picture to be replaced by a dog picture when used with Spanish content.

So you go to WPML > Media Translation and you click the pencil icon to edit the Spanish translation. In the resulting dialog you upload a dog picture to replace the cat.

When you click save it triggers an ajax request with the action wpml_media_save_translation, which handles the required changes.

What are those changes?

Well, the existing Spanish attachment post (with the cat) that is connected via the wp_icl_translations table to the original English attachment post gets updated.

In wp_posts the guid is updated to point to the url of the dog image file (replacing the cat image file url), and in wp_postmeta the corresponding rows for the keys _wp_attached_file and _wp_attachment_metadata, each of which points to the image file.

Note it is simpler if the original cat image had not already been duplicated to Spanish (which is the norm with WPML 4.8+), because there is no existing attachment post to modify, just a new one to create (and connect to the original language attachment, for which wpml_set_element_language_details would be a useful public API hook: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#hook-6013617).

That's "all" there is to it with respect to displaying the dog image instead of the cat image when viewing Spanish content that uses this pet image.

However the client implements it, they will need to achieve the same result.

They might like to look through the code that handles the ajax request when saving the translation of the image mentioned earlier, i.e. wpml_media_save_translation.

That happens in plugins/wpml-media-translation/classes/media-translation/class-wpml-media-save-translation.php. The hook is set up on line 54:

	public function add_hooks() {
		add_action( 'wp_ajax_wpml_media_save_translation', array( $this, 'save_media_translation' ) );
	}

So the function that actually handles the submission is in the same file, save_media_translation.

One option for the client would be to use the same action with a later priority (e.g. 11) to run some code, but only if this were the context where they wanted to intervene (after saving a translated image). They may have ideas for their workaround about somewhere else that would be appropriate.