Created
October 14, 2018 08:46
-
-
Save insaurabh/bfae213c979f28108ac457e14b4ec608 to your computer and use it in GitHub Desktop.
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
<?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