Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching WooCommerce product variation does not replace product image #108

Open
pumka opened this issue Mar 28, 2020 · 2 comments
Open

Comments

@pumka
Copy link

pumka commented Mar 28, 2020

WooCommerce should normally replace main product image on front-end with a variation image when you select a variation (or scroll to the image in the product gallery if it's present there).
We found that WooCommerce stops doing that if using global media gallery for variation images.

We investigated the issue and found that it happens because variation image data objects have all properties blank due to wc_get_product_attachment_props function not able to handle global media ID as it uses get_post() to load the image data.

We found that it could be fixed by implementing 'woocommerce_available_variation' filter which is called from \WC_Product_Variable::get_available_variation. Basically, if the variation data array passed to the filter has "image_id" element with a global image ID, we switch to the main site, call wc_get_product_attachment_props for a local image ID and replace "image" element of the array with the result returned, the restore current site.

Could this be implemented in future versions?
I can try suggesting a fix via pull request if needed.

@widoz
Copy link
Collaborator

widoz commented Mar 29, 2020

I found there's the problem in the back-office too, where setting the thumbnail for a variation the ID need to be handled.

It's probably worth another issue but since it's more or less related I would like know how do you are able to set the thumbnails for variations.

I was trying to replicate the issue, so I created a new variable product and trying to set a thumbnail for a variation.

Problem is that when I go to save/update the variation the set_post_thumbnail function called by \WC_Product_Data_Store_CPT::update_post_meta cannot get the right thumbnail id because internally it calls get_post.

Could this be implemented in future versions?
I can try suggesting a fix via pull request if needed.

Any help is always appreciated, please go head if you want to create a fix :)

@pumka
Copy link
Author

pumka commented Mar 30, 2020

Somehow I didn't face that problem at back-end and can assign variation images with global IDs w/o a problem. I couldn't find where \WC_Product_Data_Store_CPT::update_post_meta calls get_post actually. But we run rather outdated WooCommerce version 3.7, so chances are it was added since that version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants