I would like to display a brand logo on my product pages. I use Advanced Custom Fields (ACF) to insert the image on the taxonomy "Brand".
https://snipboard.io/JcYvM4.jpg
I have tried the code below, and tried to do as on the page here, but it doens’t work…
https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
*The image return format is "Array".
function action_woocommerce_before_variations_form( ) {
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$image = get_field('brand_logo', $taxonomy . '_' . $term_id);
echo '<img src="'.$image['url'].'" />';
};
// add the action
add_action( 'woocommerce_before_variations_form', 'action_woocommerce_before_variations_form', 10, 0 );
2
Answers
You can try like this:
The woocommerce_before_variations_form is call on product page.
So if when you call
get_queried_object()
WordPress will return Product Object, not brand term.So