Friday , December 20 2024

How to display a product attribute anywhere in Woocommerce

With this code, you can display a product attribute in the template, for example, “size”.

global $product;
echo $product->get_attribute('size');

Below I publish a method for displaying a property with an additional icon output, if this property is filled in:

<?php
$subheadingvalues = get_the_terms( $product->id, 'pa_time');
if ($subheadingvalues): ?>
<div class="labeltime"><i class="fa fa-clock-o" aria-hidden="true"></i> 
<?php foreach ( $subheadingvalues as $subheadingvalue ):
echo $subheadingvalue->name;
echo '</div>';
endforeach;
endif; ?>

In this example, time is an attribute slug.

About admin

Hi there! My name is Iryna, I am a web developer from Ukraine. While working on freelance projects I often face different technical issues and in this blog I publish articles on how to solve them. I am also interested in digital drawing and in this blog you will find brief tutorials that helped me and hopefully can help you as well.

Check Also

How to remove 404 //fonts.gstatic.com and //fonts.googleapis.com from WordPress head section

I tried solutions with functions that should remove from head and , but a very …

Leave a Reply

Your email address will not be published. Required fields are marked *