How To Loop Through WooCommerce Attributes

Trying to loop through WooCommerce attributes outside a WooCommerce products page? All you may need is to use the correct terms and show empty categories.

Looping through WooCommerce attributes

To loop through WooCommerce attributes, we need to understand that WooCommece adds the pa_ prefix to these.

$terms = get_terms( 'pa_yourattribute' , array( 'hide_empty' => false ) );
foreach( $terms as $term ) :
    echo $term->name
endforeach;

Notice, that we’ve added the hide_empty attribute when getting the terms. On default, WooCommerce will only show terms with products listed inside of them.