Viewing 15 replies - 1 through 15 (of 31 total)
  • I need this as well.

    Me too.. anyone found a solution?

    I’ve found a paid plugin ($25) that does the trick: https://codecanyon.net/item/wooswatches-woocommerce-color-or-image-variation-swatches/7444039. Haven’t tried it yet let me know if you’ve tested it.

    I know this plugin, but I already use the Themealien plugin and If I install this paid one I’m scared that it will erase all my variable products made with this free plugin.
    I’m sure that it’s possible to be done with this existing plugin, but I don’t have enough skills in php :/

    I, too, had this problem. I installed this free plugin (https://wordpress.org/plugins/variation-swatches-for-woocommerce/) by ThemeAlien.

    It didn’t erase any of my current variables, but I did have to set up a whole new set of variations. To have it coded in PHP without you having to re-program the variables would be expensive, and would take more time than just re-doing the variables in this plugin.

    If you are really afraid of losing your current variables, backup the site before installing this plugin. I couldn’t find anything without using a plugin.

    Best of luck!

    • This reply was modified 6 years, 9 months ago by dallasmac.
    Thread Starter Saurabh Jain

    (@saurabhj91)

    Hi @dallasmac, @sophiemarquise and @rvandenbussche I have implemented the same using below code, hope it will help you as well.

     add_action( 'woocommerce_after_shop_loop_item', 'sm_display_product_color_options', 9 );
    function sm_display_product_color_options(){
    	global $woocommerce, $product;
    	$variation_colors_data = $product->get_attributes();
    	$variation_colors_data = $variation_colors_data['pa_color'];
    	$variation_colors = $variation_colors_data['options'];
    	echo "<div class='product_colors_container'>";
    	foreach ($variation_colors as $variation_color) {
    		echo "<div class='product_color_options' style='background-color:".get_term_meta($variation_color,'color',true)."'></div>";
    	}
    	echo "</div>";
    } 

    And some css to fit in my theme.

    • This reply was modified 6 years, 9 months ago by Saurabh Jain.

    Hi @saurabhj91 !
    Thank you so much for this code! 🙂

    I’ve found an alternative way to hook entry-summary in shop page, but I think it’s not a very “clean” solution and your snippet is a way better.

    Did you figured out how to switch image?

    @saurabhj91 I can’t seem to get it to work. I’ve tried to change the ‘pa_color’ but doesn’t do a thing. I also don’t know what I need to fill in in the “$variation_colors = $variation_colors_data[‘options’];”

    Let me know if you have an idea. I’m working on https://speedropeshop.de

    Thread Starter Saurabh Jain

    (@saurabhj91)

    @rvandenbussche replace the pa_color with your attribute slug. you can check it in the attributes section.

    Hey @saurabhj91, in which file did you put the code above ? Thanks 🙂

    Thread Starter Saurabh Jain

    (@saurabhj91)

    @thmsggn you can add the code in functions.php

    @saurabhj91 I think I’ve tried that already, but will retry it tonight. I also use image-swatches instead of colour-swatches. Probably I need to modify the outputted HTML anyway, but let’s first get something on the screen.

    Thanks @saurabhj91! Your efforts are appreciated.

    I put it in functions.php and replaced pa_color by my attribute slug but i have nothing on my shop page / product list page. Do i need to replace something else ? @saurabhj91
    Thanks for your help !

    @thmsggn Can you please provide the website you’re working on? Without it would be guesswork.

    Well i can’t, i’m not allowed to share the website until he is done… :/

Viewing 15 replies - 1 through 15 (of 31 total)
  • The topic ‘How to get color swatches on product list page?’ is closed to new replies.