获取自定义分类法的ACF字段的语法为:
$var = get_field(\'name_of_acf_field\', \'name_of_taxonomy\' . \'_\' . taxonomy_ID);
因此,在您的情况下,您需要先获取product\\u cat ID,然后执行以下操作:
add_action( \'woocommerce_shop_loop_item_title\', \'VS_woo_loop_product_title\', 10 );
function VS_woo_loop_product_title() {
echo \'<h3>\' . get_the_title() . \'</h3>\';
$terms = get_the_terms( $post->ID, \'product_cat\' );
if ( $terms && ! is_wp_error( $terms ) ) :
//only displayed if the product has at least one category
$cat_links = array();
foreach ( $terms as $term ) {
$cat_links[] = $term->name;
$cat_id = $term->term_id;
}
$on_cat = join( " ", $cat_links );
$bgcolor = get_field(\'kollekcio_szine\', \'product_cat\' . \'_\' . $cat_id);
?>
<div style="background-color: <?php echo $bgcolor; ?>">
<?php echo $on_cat; ?>
</div>
<?php endif;
}