Color swatches on category page?
Question
I’m trying to add color swatches on category page.
I have this code in functions.php :
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='variable-item-span variable-item-span-color' style='background-color:".get_term_meta($variation_color,'color',true)."'></div>";
}
echo "</div>";
}
and this is the output:
<div class="product_colors_container"><div class="variable-item-span variable-item-span-color" style="background-color:"></div><div class="variable-item-span variable-item-span-color" style="background-color:"></div></div>
Any idea what’s wrong?
Thanks.
Andrei
0
customization
5 years
2018-09-28T05:23:48-05:00
2018-09-28T05:23:48-05:00 0 Answers
105 views
0
Leave an answer