Skip to content

Instantly share code, notes, and snippets.

@insaurabh
Created October 14, 2018 08:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save insaurabh/bfae213c979f28108ac457e14b4ec608 to your computer and use it in GitHub Desktop.
Save insaurabh/bfae213c979f28108ac457e14b4ec608 to your computer and use it in GitHub Desktop.
<?php
// get the attribute
add_action( 'woocommerce_shop_loop_item_title', 'show_attribute_custom_action', 15 );
function show_attribute_custom_action() {
global $product;
$sizeAttribute = array_shift( wc_get_product_terms( $product->id, 'pa_size', array( 'fields' => 'names' ) ) );
$descAttribute = array_shift( wc_get_product_terms( $product->id, 'pa_description', array( 'fields' => 'names' ) ) );
if($sizeAttribute && !$descAttribute){
echo "<span class='sizeAttribute'> $sizeAttribute </span>";
}
if(!$sizeAttribute && $descAttribute){
echo "<span class='descAttribute'> $descAttribute </span>";
}
if($descAttribute && $sizeAttribute) {
echo "<span class='sizeAttribute'> $sizeAttribute </span>";
echo " - <span class='descAttribute'> $descAttribute </span>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment