Skip Navigation

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: 

This topic contains 4 replies, has 3 voices.

Last updated by Dražen 1 year, 5 months ago.

Assisted by: Dražen.

Author Posts
January 18, 2024 at 10:05 pm #15202450

andriusB-4

I am trying to: load Woocommerce product images with AJAX. In original language they load fine but in translation, $product->get_image_id() returns "".

Link to a page where the issue can be seen:hidden link

I expected to see: images

Instead, I got: no images

January 19, 2024 at 12:13 pm #15204814

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello @andriusB-4, welcome to the WPML support forum!

While you are waiting for one of my colleagues to take this ticket and work on it, let me provide you with first debugging steps or if I can perhaps help with the issue quickly.

Could you please check if the AJAX cookie option is enabled? https://wpml.org/documentation/getting-started-guide/language-setup/enabling-language-cookie-to-support-ajax-filtering/#:~:text=To%20enable%20language%20information%20for,language%20filtering%20for%20AJAX%20option.

If the issue persist, please enable WP_Debug and WP_Debug_log on your website, then reproduce the issue and check the debug log in the wp-content folder. it will display more details about the error: https://wpml.org/documentation/support/debugging-wpml/

Please let us know if it works.

January 19, 2024 at 12:51 pm #15205033

andriusB-4

Yes, ajax was always enabled I checked that before posting this ticket.
Logging is enabled but there are now errors just image_ids are not stored within WC_Product object.

January 19, 2024 at 3:13 pm #15205516

andriusB-4

I wrote this function to solve the issue for me. Please review and let me know if this is the right way to work around the problem:

function anbo_show_translated_product_images($value, $product) {
if (empty($value)) {
// Remove the filter to prevent an infinite loop
remove_filter('woocommerce_product_get_image_id', 'anbo_show_translated_product_images', 10);

// Fetch the original product and get its image ID
$default_language = apply_filters('wpml_default_language', NULL);
$original_product_id = apply_filters('wpml_object_id', $product->get_id(), 'product', true, $default_language);
if ($original_product_id !== $product->get_id()) {
$original_product = wc_get_product($original_product_id);
$value = $original_product ? $original_product->get_image_id() : '';
}

// Re-add the filter
add_filter('woocommerce_product_get_image_id', 'anbo_show_translated_product_images', 10, 2);
}
return $value;
}
add_filter('woocommerce_product_get_image_id', 'anbo_show_translated_product_images', 10, 2);

January 22, 2024 at 8:06 am #15209651

Dražen
Supporter

Languages: English (English )

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

Hello,

at first glance, it looks fine, but we can not know what else plugin or code you are using, so I suggest testing it first on staging.

As for the issue, we can not support custom code or provide custom coding service, if you wish to continue us checking, we can provide a test site and you can replicate the issue there with only WPML plugins and the default WP theme, to confirm this is a WPML bug/issue.

Let me know.

Regards,
Drazen