Created
March 12, 2017 19:18
-
-
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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