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