Could you help me a little, I cant figure out the right solution. (SINGLE PRODUCT PAGE TEMPLATE)
I try to use to render the brand image what I uploaded in built in Woocommerce Brands.The brand text I can render, but the image is not.
I tried out lots of solutions and finally tried to write custom dynamic tag code for it, but not working. (In query loop can render easy the brand image.)
- {post_terms_product_brand:image}
- {post_terms_product_brand:value}
- {post_terms_product_brand:thumbnail_id}
And tried to write custom tag and it isnt working too.I would like to use simple dynamic tag and not code element.
custom dynamic tag: {product_brand_image}
Code:// Add WooCommerce Brand Image Dynamic Tag
add_filter(‘bricks/dynamic_tags_list’, function($tags) {
$tags = [
‘name’ => ‘{product_brand_image}’,
‘label’ => ‘Product Brand Image’,
‘group’ => ‘WooCommerce’
];
return $tags;
});
// Render WooCommerce Brand Image
add_filter(‘bricks/dynamic_data/render_tag’, function($result, $tag, $post_id) {
if ($tag !== ‘product_brand_image’) {
return $result;
}
// Get the product's brand terms
$terms = get_the_terms($post_id, 'product_brand');
if (!empty($terms) && !is_wp_error($terms)) {
$brand_term = $terms[0]; // Get first brand
$thumbnail_id = get_term_meta($brand_term->term_id, 'thumbnail_id', true);
if ($thumbnail_id) {
// Return the image URL
return wp_get_attachment_url($thumbnail_id);
}
}
return '';
}, 10, 3);