admin管理员组文章数量:1122846
I've been trying to get a Woocommerce product's tags inside a twig template. I want to search for a specific tag so that I can assign a class on the product grid which is inside the tease product twig template. I've been searching the web all day but can't find any info and the Timber documentation has only the basic layout for a tease product template.
The code I have is the following which is obviously not working:
{% for item in products %}
{% set link = item.link %}
{% set img_src = item.thumbnail.src('shop_single') %}
{% if (grid_type == 'categories') %}
{% set img_src = Image(item.meta('thumbnail_id')) %}
{% if img_src == '' %}
{% set img_src = placeholderImg %}
{% endif %}
{% set link = item.link %}
{% endif %}
{% if item in taxonomy.findTaxonomy({'tag':'BF24'}) %}
{% set tagclass='bf24' %}
{% else %}
{% set tagclass='' %}
{% endif %}
<div class="item flex justify-center {{tags}} ">
<a href="{{link}}">
<div class="overflow-hidden rounded-full w-[240px] h-[190px] bg-slate-100"><img class="w-full h-full object-cover" src="{{img_src}}" alt=""></div>
<div class="title text-2xl py-2 rounded-full px-2 {{titles_bg}} max-w-[240px] text-center font-medium">{{item.title}}</div>
{# {% do action( 'woocommerce_after_shop_loop_item_title' ) %} #}
{% do action( 'woocommerce_before_add_to_cart_form' ) %}
{% if hide_titles == false %}
{% endif %}
</a>
</div>
{% endfor %}
I've tried the following code
{% if item in taxonomy.findTaxonomy({'tag':'BF24'}) %}
{% set tagclass='bf24' %}
{% else %}
{% set tagclass='' %}
{% endif %}
and even tried passing the tags from the woocommerce.php file to the archive.twig and then tease-product.twig template. No success with that since I don't know how to pass the product tags with this code which is inside the woocommerce.php file:
$posts = Timber::get_posts();
$context['products'] = $posts;
本文标签: wordpressGet Woocommerce product tags inside twig template for tease productStack Overflow
版权声明:本文标题:wordpress - Get Woocommerce product tags inside twig template for tease product - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736299713a1930554.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论