Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Yorlinq/215e5dcfd54c8b5e08b80096fd9ef551 to your computer and use it in GitHub Desktop.
Save Yorlinq/215e5dcfd54c8b5e08b80096fd9ef551 to your computer and use it in GitHub Desktop.
Shortcode for 'Product category name' by 'Product category id' - WooCommerce
// Shortcode for 'Product category name' by 'Product category id': [yl_product_category_name cat_id='']
function yl_product_category_name_shortcode( $atts ) {
$atts = shortcode_atts( array(
'cat_id' => '',
), $atts );
if ($term = get_term_by( 'id', $atts['cat_id'], 'product_cat' ) ){
return $term->name;
}
}
add_shortcode('yl_product_category_name','yl_product_category_name_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment