C
C
Chingiz Huseynov2020-10-18 17:00:44
WordPress
Chingiz Huseynov, 2020-10-18 17:00:44

How can the attribute value be made a link to the product card?

Hello. Can anyone suggest how to implement the following idea? There are 3 products in the same category, but with different attribute values. I plan to display these values ​​in the product map. Assume a "color" attribute with values ​​"red", "green", "blue". How to convert values ​​into a link to a product in the format ( https://site.ru/product/product name /).

Here, here I tried to display it in this way, but it throws me into the archive of the product and the link is formed wrong ( https://site.ru/color/blue/ )

<?php $product_colors = get_terms(array('taxonomy' => 'pa_color', 'hide_empty' => false)); ?>
                
                <?php if ($product_colors) : ?>

                    <h3 class="single-product-page__title filter__sidebar-title">Цвет</h3>
                    <div class="single-product-filter">
                        <?php foreach ($product_colors as $product_color) : ?>
                            <li class="color-block"><a href="<?php echo get_term_link($product_color) ?>"><?php echo $product_color->name ?></a></li>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>


Share your experience with a newbie. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pychev Anatoly, 2020-10-18
@pton

An alternative can be seen here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question