Created
June 17, 2015 10:47
-
-
Save Veesibility/437a07e823706596be88 to your computer and use it in GitHub Desktop.
Woocommerce - Display Product Category Title on Shop Page
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
/** This code should be added to functions.php of your theme **/ | |
/* Woocommerce - Display Product Category Title on Shop Page */ | |
add_action( 'woocommerce_before_shop_loop_item_title', 'vee_add_product_cat', 25); | |
function vee_add_product_cat() | |
{ | |
global $product; | |
$product_cats = wp_get_post_terms($product->id, 'product_cat'); | |
$count = count($product_cats); | |
foreach($product_cats as $key => $cat) | |
{ | |
echo | |
'<span class="vee_category_title"> | |
<span class="vee_category_title_'.$cat->slug.'">'.$cat->name.'</span></span>'; | |
if($key < ($count-1)) | |
{ | |
echo ' '; | |
} | |
else | |
{ | |
echo ' '; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works when a category is selected, but also displays the first category when no category is selected.