Categories – How to set acf color field as background color in product category

I have set an acf color picker field for woocommerce product category. I want to set this color as the background of the name of the category which I have printed on the product page. I’ve tried setting the bg color value, but it doesn’t work.

The color picker field is named kollekcio_szine.

Here is my code:

<?php echo $product->get_categories( ', ', '<span class="termek-oldal-kategoria-teszt"> style="background-color:<?php the_field('kollekcio_szine'); ?>"' . _n( 'Category:', 'Categories:', sizeof( get_the_terms( $post->ID, 'product_cat' ) ), 'woocommerce' ) . ' ', '.</span>' ); ?>

Can you help me how to do this please?

Leave a Comment