Show custom taxonomy on page using twig and woocommerce

Viewed 28

Within Woocommerce I'm trying to get the values of a custom taxonomy to show on product page. Using Twig for the first time.

This is the custom taxonomy:

    class WC_Product_Taxonomies_tags {
    private $extra_wc_taxonomies = [
        'size' => [
            'S',
            'M',
            'L',
            'XL'
        ],
        'color' => [
            'Black',
            'Blue',
            'Green'
        ]
    ];

In my php page:

    $context['extra_wc_taxonomies'] = Timber::get_terms('size');

In my twig file:

    <div class="extra-tags">
                {% for item in extra_wc_taxonomies %}
                    <li>
                        <p>{{ item.name('size') }}</p>

                    </li>
                {% endfor %}
            </div>

Now it is showing the values but it is showing all of them. I need it to show only the ones I selected on product page in admin woocommerce.

The fields are created with ACF:

    {
    "key": "group_54dg7878ch53x12",
    "title": "Extra Taxonomies",
    "fields": [
  
        {
            "key": "field_34t67d99h783",
            "label": "Choose size:",
            "name": "acf_size",
            "type": "taxonomy",
            "instructions": "",
            "required": 0,
            "conditional_logic": 0,
            "wrapper": {
                "width": "50",
                "class": "",
                "id": ""
            },
            "taxonomy": "size",
            "field_type": "checkbox",
            "add_term": 0,
            "save_terms": 1,
            "load_terms": 1,
            "return_format": "object",
            "multiple": 0,
            "allow_null": 0
        },
        {
            "key": "field_34t67d99h123",
            "label": "Select Color",
            "name": "acf_color",
            "type": "taxonomy",
            "instructions": "",
            "required": 0,
            "conditional_logic": 0,
            "wrapper": {
                "width": "50",
                "class": "",
                "id": ""
            },
            "taxonomy": "color",
            "field_type": "checkbox",
            "add_term": 0,
            "save_terms": 1,
            "load_terms": 1,
            "return_format": "object",
            "multiple": 0,
            "allow_null": 0
        }
    ],
    "location": [
        [
            {
                "param": "post_type",
                "operator": "==",
                "value": "product"
            }
        ]
    ],
    "menu_order": 0,
    "position": "normal",
    "style": "default",
    "label_placement": "top",
    "instruction_placement": "label",
    "hide_on_screen": "",
    "active": true,
}

All help is appreciated.

0 Answers
Related