You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 :)
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.
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.
The text was updated successfully, but these errors were encountered: