Skip to content

Instantly share code, notes, and snippets.

@tdmrhn
Last active August 4, 2022 11:38
Show Gist options
  • Save tdmrhn/c366f6c980df3724951b8650cbd621ab to your computer and use it in GitHub Desktop.
Save tdmrhn/c366f6c980df3724951b8650cbd621ab to your computer and use it in GitHub Desktop.
Display Attributes in Product Loop Card
add_action( 'blocksy:woocommerce:product-card:title:after', 'display_attribute_for_variations_size' );
function display_attribute_for_variations_size(){
global $product;
$taxonomy = 'pa_size';
if ( $product->get_type() == 'variable' ) {
$output = array();
foreach ($product->get_available_variations() as $values) {
foreach ( $values['attributes'] as $attr_variation => $term_slug ) {
if( $attr_variation === 'attribute_' . $taxonomy ){
$output[$term_slug] = get_term_by( 'slug', $term_slug, $taxonomy )->name;
}
}
}
if ( sizeof($output) > 0 ) {
echo '<div class="'.$taxonomy.'-variations-terms">' . implode( ', ', $output ).'</div>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment