I want to create a shortcode for my wp+woocommerce site, that will show the name of the current products category. I get the category id from my url with get request – this is a specialty. It will look something like:
function this_product_category_name() {
$cat_id = (int) str_replace('-product_cat', '', $_GET['really_curr_tax']);
// here must be a string to get the $cat_name from $cat_id;
echo $cat_name;
}
add_shortcode( 'this_product_category_name', 'this_product_category_name' );
What can be the solution?
2
Answers
Since you’re on the
product category
page, then you could useget_queried_object
, and then from that object you could get thename
like so:Let me know if that’s what you’re looking for.
So your code would be something like this:
Use
get_term_by()
.USEFUL LINKS