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 33 replies, has 2 voices.

Last updated by Alejandro 3 months, 3 weeks ago.

Assigned support staff: Alejandro.

Author Posts
May 16, 2019 at 2:34 pm

katieW-3

I am trying to:Change product images on translated product pages hidden link
vs hidden link

I expected to see: Different images on French page

Instead, I got: Same images as UK English page

May 16, 2019 at 4:17 pm
May 21, 2019 at 11:08 am #3854629

Alejandro
Supporter

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

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

Hello, our devs told us that this was indeed a bug and that it will be fixed in the next version, so in the meantime i'll change the status of this post to "Fixed in next Release" (and will try to find a workaround for you, in the meantime)

May 23, 2019 at 2:44 pm #3877035

katieW-3

Thank you for the reply. can you please let us know when will be the next updated version available? it's kind of critical situation for our project as the site goes live in 10 days. or if you guys have different solutions for that please let us know.

Regards

May 28, 2019 at 3:57 pm #3908639

katieW-3

Hello,

Thanks for the recent update, that seems to have at least on the WordPress admin side fixed things so for example:

hidden link

vs.

hidden link

The latter is a translation of the former, and we can now select different gallery images independently and all is good and updates fine.

What doesn't seem to work is on the front end, so when we look at the pages respectively:

hidden link

vs.

hidden link

The top left is the image gallery carousel.

We pull them in using this code:

   $product_id = get_the_id();
    $product = wc_get_product($product_id);

    

    if($product):
           $product_images = sprintf('<div class="%1$s"><img src="%2$s" alt="%3$s"/></div>','in__product-image',get_the_post_thumbnail_url( $product->get_id(), 'full'), get_post_meta($product->get_id(), '_wp_attachment_image_alt', true));

            $product_gallery_images = $product->get_gallery_image_ids();

           

            foreach($product_gallery_images as $pgi):
                $pgi_src = wp_get_attachment_image_src( $pgi, 'full');
                $product_images .= sprintf('<div class="%1$s"><img src="%2$s" alt="%3$s"/></div>','in__product-image',$pgi_src[0], get_post_meta($pgi, '_wp_attachment_image_alt', true));
            endforeach;

           return sprintf('<div class="%1$s">%2$s</div>','in__images-carousel owl-carousel',$product_images);
    endif;

The code correctly gets the respective post IDs but the call to:

$product_gallery_images = $product->get_gallery_image_ids();

Whilst it shows IDs being different, it only shows the 4 image IDs returned on the US translation, i.e. not including the additional 5th image added (of the building and van) doesn't appear.

And we're not sure why. Is there some interaction with WPML and WooCommerce that hasn't been accounted for since this bug being fixed?

Or is our code in some way not right?

Thanks,
Vicky

May 30, 2019 at 3:30 pm #3924219

Alejandro
Supporter

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

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

Hello!

The problem should be fixed with WooCommerce Multilingual version 4.6.3, and this is what you need to do:

1) Disable the translation editor on that page (by turning off the WPML switch for that page)
2) In the same page, disable the option "duplicate gallery images" (it's right below the save/update product section)
3) Go to the page and now you should be able to add your desired gallery images independently of the language.

Regards.

May 31, 2019 at 8:11 am #3928405

katieW-3

Hello Alejandro,

I'm afraid that is exactly what we have done for this product and what we would do for others.

We have unchecked "Duplicate uploaded media from original" and "Duplicate featured image from original" having disabled the WPML translation editor.

We can add the desired gallery images but as I note when we view the page live on the site it doesn't pick up the images we have added, it still seems to only show the ones that come from the parent/default language copy of the product.

Please see here:

hidden link
(Front end page: hidden link)

vs

hidden link
(Front end page: hidden link)

The US one has an extra image for testing purposes of a silver van in front of a building, the UK (default lang) doesn't.

Vicky

May 31, 2019 at 3:00 pm #3931461

Alejandro
Supporter

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

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

Hello,

There must be an issue with the code because i changed the theme (very, very briefly) to storefront and the gallery appeared correctly (all 5 images + featured) but the code seems to be alright at first sight.

I also added a new image to the gallery, so i could rule out a missing loop cycle, and that doesn't seem to be the case either.

At this point i suggest you do a var_dump() on maybe both instances of:

$product_images

and check if by any chance that could give you a hint on what's going on.

Regards.

May 31, 2019 at 4:27 pm #3932061

katieW-3

Thanks,

Yes we tried var_dumping $product_images and it only contained 4 IDs for the gallery, not 5.

Which makes me think there has to be something wrong somewhere as we can only display what the WooCommerce functions send back to us.

Vicky

May 31, 2019 at 4:29 pm #3932089

katieW-3

p.s. changing the theme would have had an effect as it would have reverted to the standard WooCommerce product page, rather than our customised environment to use a Divi template, which itself uses a shortcode (which uses the code I pasted above) to fetch the gallery images.

June 3, 2019 at 4:57 pm #3944681

Alejandro
Supporter

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

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

Oh so if i understand correctly, the code you sent me above is from a shortcode that comes from Divi directly, it's not a custom code you created, correct?

Would you mind pointing me to the correct shortcode (or send me the steps to recreate the page from scratch) so i can have our developers test it? because as you mention it, it sounds more as a Divi related issue (maybe a compatibility issue) than anything else.

And if that's the case i'll have to replicate the problem from scratch or at least know how to do so (our development team will ask for this).

Regards

June 4, 2019 at 8:55 am #3949387

katieW-3

No, this is a custom shortcode. The entirety of the code is above. We are using Divi but I add the above as a shortcode in our child theme.

June 4, 2019 at 9:53 am #3950001

katieW-3

Hi Alejandro,

I looked at the object returned from wc_get_product with the product ID.

So the US post ID for the post I am trying to get the extra images to display on is 29279, the native language post ID is 29258 and I can confirm that wc_get_product's object starts with:

"id":29279

So we know we're in the right post, however the node

"gallery_image_ids":[15807,15816,15825,15834]

Cites only 4 images, the 4 original images.

So given that wc_get_product is not returning the additional image IDs from this post, even though they are there, there must be something about the way WooCommerce and WPML and not quite working properly, because the only code executed to see this result is:

function in__wp_sc_productimages(){
    $product_id = get_the_id();
    $product = wc_get_product($product_id);
...

So you can't really go wrong with those two lines!

From then on the code can only display what it is told to, and the IDs are incomplete.

I understand you used the Storefront theme, which may have knocked out some of our menus which we've had to reconfigure -- so please check before doing that agai.

As I say we are using Divi + a plugin to use custom Divi layouts to display products, not the built in WooCommerce product template and maybe that obtains gallery images in a different way?

Beyond this I don't know what else we can do as it appears we are doing everything in a clean and correct manner, but wc_get_product is not returning the object with all the necessary image IDs.

Thanks,
Vicky

June 4, 2019 at 10:25 am #3950335

katieW-3

Hiya,

URGENT:

I'm guessing someone is in looking at this as a whole batch of plugins have been disabled, can we make sure that by 12.30pm BST (11.30am UTC) that the plugins are all re-enabled as we have a client meeting and need the site to be presentable.

Appreciate the time being spent looking at the issue though!

Thanks.

June 4, 2019 at 11:13 am #3950877

katieW-3

Hiya,

I'm afraid I have to start activating plugins - as the client meeting is in 15 minutes time. I appreciate this may mess things up for you, but maybe we can schedule a time when this investigation work is done just so we're not tripping over eachother.

Notably in re-enabling the plugins, it was only when WooCommerce Multilingual plugin v4.6.3 was enabled that the problem with the missing images came back in, disabling it, they came back.

I will need to log all admin users out and change the password, because I need to make sure nobody is tinkering with the site during the client demo.

Thanks,
Vicky

The topic ‘[Closed] Can't change Product Gallery Images on translated WooCommerce products’ is closed to new replies.