Skip to content

Instantly share code, notes, and snippets.

@rynaldos-zz
Last active September 20, 2021 23:53
Show Gist options
  • Save rynaldos-zz/38ca1943598f7dd013a48f4c3796c333 to your computer and use it in GitHub Desktop.
Save rynaldos-zz/38ca1943598f7dd013a48f4c3796c333 to your computer and use it in GitHub Desktop.
[WooCommerce 3.0] show categories / links above product title in shop / archive page
add_action( 'woocommerce_before_shop_loop_item_title', 'add_category_title', 25);
function add_category_title()
{
global $product;
$product_cats = wp_get_post_terms($product->get_id(), 'product_cat');
$count = count($product_cats);
foreach($product_cats as $key => $cat)
{
echo
'<span class="wcc_category_title">
<span class="wcc_category_title_'.$cat->slug.'">'.$cat->name.'</span></span>';
if($key < ($count-1))
{
echo ' ';
}
else
{
echo ' ';
}
}
}
//Did this help? Donate me some BTC: 1BEsm8VMkYhSFJ92cvUYwxCtsfsB2rBfiG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment