I have set an acf color picker field for woocommerce product category. I would like to set this color as a background to the category name that I've printed on the product page. I've tried to set the bg color value, but it doesn't work.
The name of the color picker field is kollekcio_szine.
Here's 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>' ); ?>
Could you help me how to do that, please?
I have set an acf color picker field for woocommerce product category. I would like to set this color as a background to the category name that I've printed on the product page. I've tried to set the bg color value, but it doesn't work.
The name of the color picker field is kollekcio_szine.
Here's 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>' ); ?>
Could you help me how to do that, please?
The style-attribute is not in the span-tag, but should be. Further you are using the php opening tag inside of the echo tag (copy-paste?).
change
'<span class="termek-oldal-kategoria-teszt"> style="background-color:<?php the_field('kollekcio_szine'); ?>"'
to
'<span class="termek-oldal-kategoria-teszt" style="background-color:'.get_field('kollekcio_szine') . '">'
(sorry, I would have commented, but I don't have enough reputation)