categories - How to set acf color field as background color to product category

admin2025-01-08  5

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?

Share Improve this question asked Sep 17, 2020 at 13:52 BenBen 33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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)

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736266941a1162.html

最新回复(0)