Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save emoop/1f28eb28adb1ac85aa7e3a3dfbd3e23a to your computer and use it in GitHub Desktop.
Save emoop/1f28eb28adb1ac85aa7e3a3dfbd3e23a to your computer and use it in GitHub Desktop.
Display attributes names for each product in shop catalog in format like "size:x,xxl"
add_action( 'woocommerce_after_shop_loop_item_title','display_sizes' );
function display_sizes(){
global $product;
$variations=$product->get_available_variations();
$count=sizeof($variations);
$counter=0;
echo '<span class="sizes">Sizes:';//sizes or whatever u want
foreach($variations as $var){
foreach($var['attributes'] as $name=>$val){
$counter++;
$term=get_term_by('slug',$val,str_replace('attribute_','',$name));
echo $term->name;
if($counter!=$count)
{
echo ',';
}
}
}
echo '</span>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment