Home › Forums › WoodMart support forum › Change image based on color
Change image based on color
- This topic has 9 replies, 2 voices, and was last updated 2 years, 3 months ago by Elise Noromit.
-
AuthorPosts
-
August 11, 2021 at 4:50 pm #312085
ZimmerParticipantHello,
First of all, Thank you for this great theme.
Based on the woocommerce default behavior I know that when you have 2 attributes like (color + size ) until all these two attributes will not be selected the variation image will not be changed. So, my question is below:In the attribute swatches, I’ve chosen color as a default Grid swatch attribute to display and on the main shop page, I can choose the color and the variation image will be changed.
My question: Is it possible to do the same on the product page? If yes, then please share the snippet or code.Thank you.
August 11, 2021 at 6:58 pm #312095
Elise NoromitMemberHello,
Thank you very much for choosing our theme and for your warm feedback.
The swatches are just visual customization of the Woocommerce default attribute, so if the variation is created basing on size and color, you need to choose both to select and add to the cart.
If you want to select variation only by color, you need to create variation only on the color attribute.
If you have any questions please feel free to contact us.
Best Regards
August 11, 2021 at 7:49 pm #312098
ZimmerParticipantYes, I understand that, but I’m selling products that need two variations (color and size) but I want my customers to let them switch images based on color selection. In the same way, as it is done in the screenshot.
https://prnt.sc/1mzxr6sIs it possible to do the same on the product page? I assume it’s is possible to implement with JS or JQuery.. but I’m not sure how 🙁
August 12, 2021 at 12:45 am #312127
Elise NoromitMemberHello,
Yes, that is possible. Please read and follow this detailed manual: https://xtemos.com/docs/woodmart/variable-products-swatches/
If you have any questions please feel free to contact us.
Best Regards
September 5, 2021 at 7:19 am #316515
ZimmerParticipantI have come across this code on SO and another site. It allows a product variation image to change when only one main attribute is selected (e.g. color), rather than having to select all variation attributes (e.g color and size) in order for the image to change.
This code was written to work with a plugin, however the person who wrote it mentioned changing line 6 in order to use without plugins. I have tried changing data-attribute_name to equal attribute_color, as it is named. I have called this code using the script tag in functions.php but not sure what else I should be doing.
How could I make this work?var image_to_show = ''; var variations = JSON.parse($(".variations_form").attr("data-product_variations")); if(variations) { var first_attr = Object.keys(variations[0].attributes)[0]; // when swatch button is clicked $("ul[data-attribute_name='"+first_attr+"'] li").click(function() { var choice = $(this).attr("data-value"); var found = false; // loop variations JSON for(const i in variations) { if(found) continue; if(variations.hasOwnProperty(i)) { // if first attribute has the same value as has been selected if (choice === variations[i].attributes[Object.keys(variations[0].attributes)[0]]) { // change featured image image_to_show = variations[i].image_src; found = true; } } } }); // after woo additional images has changed the image, change it again jQuery(".variations_form").on("wc_additional_variation_images_frontend_image_swap_done_callback", function() { if(image_to_show.length) { $(".attachment-shop_single").attr("src", image_to_show).removeAttr("srcset"); } }); }
September 5, 2021 at 6:01 pm #316586
Elise NoromitMemberHello,
Such kind of customization is not covered by our support. Please use global attributes, you can create more than one color attribute, for example, choose the color, Cloth color, and so on.
Then you can show or hide this attribute filter on the category page. You can show the Cloth color filter in the Cloth category only not to overload the sidebar.If you have any questions please feel free to contact us.
Best Regards
September 9, 2021 at 11:15 am #317464
ZimmerParticipantMay I have payable support in that case from your team? for this feature.
September 9, 2021 at 11:24 pm #317577
Elise NoromitMemberHello,
Unfortunately, we do not provide paid support, you will have to find a developer or company who would help you.
If you have any questions please feel free to contact us.
Best Regards
August 28, 2022 at 7:34 pm #400054
bhare1985ParticipantAugust 29, 2022 at 12:33 am #400094
Elise NoromitMemberHello,
We do not guarantee custom snippets. This solution was suggested by one of the site owners and we have not tested it to suggest. You can try this solution.
Best Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register