I'm trying to add an array of Advanced Custom Fields values to the single product page in a WooCommerce website.
This fields are checkboxes the website admin will check and I want the values to show in the single product page.
I've already found how to show the values using this code on my child theme's functions.php file:
add_action( 'woocommerce_product_tabs', 'deco_display_acf_field_under_images', 30 );
function deco_display_acf_field_under_images() {
echo the_field('cuidados');
}
Where “cuidados” is the name of the field.
It works, but this only displays the values separated by commas.
Now I want to use a more advanced way of displaying the values like this example I've found on the ACF documentation for displaying checkboxes values:
<?php
// vars
$colors = get_field('colors');
// check
if( $colors ): ?>
<ul>
<?php foreach( $colors as $color ): ?>
<li><?php echo $color; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
I don't know PHP but I know this won't work on my functions.php file because of the syntax.
Can you help me figure out how to achieve this?
Thanks in advance.