Corentin Branquet
Corentin Branquet

Reputation: 1576

Display all custom attributes Woocommerce

I'm working on a project where I want to display product's image and customs attributes from Woocommerce.

I already set attributes like this

enter image description here

I want in my php code display all the attributes (title et terms).

I already try <?php $product->list_attributes(); ?>. It works fine but data are displaying in <table>. I want to customize the display.

Thanks for your help !

Upvotes: 2

Views: 1209

Answers (1)

rnevius
rnevius

Reputation: 27092

Whenever I get stuck with a custom method like this in WooCommerce, I try to resort to the docs to see what is going on.

If you inspect the source for this method, you'll find that it's actually using a custom template single-product/product-attributes.php to output this table you're seeing.

In order to change the output, you have two options:

  1. Override the template via your theme
  2. Observe single-product/product-attributes.php and use the information there to write your own custom loop in your original template.

The second option means that you'll likely use the get_attributes() method, instead of list_attributes().

Upvotes: 3

Related Questions