Last active
August 4, 2022 11:38
-
-
Save tdmrhn/c366f6c980df3724951b8650cbd621ab to your computer and use it in GitHub Desktop.
Display Attributes in Product Loop Card
This file contains hidden or 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( '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