如何从woocommerce的id产品中获取类别名称 [英] How to get the category name from an id product in woocommerce

查看:32
本文介绍了如何从woocommerce的id产品中获取类别名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 woo commerce 创建一个电子商务网站.我正在为如何在 woocommerce 中使用类别 id 显示产品的类别名称的代码而苦苦挣扎.

I am creating a e-commerce website using woo commerce. I am struggling with a code that how to display the category name of the product using category id in woocommerce?.

在 wordpress 中很容易按 id 显示类别名称为 get_the_category_by_id(3).以便它显示 id 3 的名称.

In wordpress its easy to display the category name by id as get_the_category_by_id(3). So that it display the name of the id 3.

同理如何在woocommerce中按id显示分类名称?

By the same way how to display the category name by id in woocommerce?

推荐答案

试试这个功能获取产品类别名称

Try this function to get product category name

function get_product_category_by_id( $category_id ) {
    $term = get_term_by( 'id', $category_id, 'product_cat', 'ARRAY_A' );
    return $term['name'];
}
$product_category = get_product_category_by_id( $your_category_id );

希望这会有用.

这篇关于如何从woocommerce的id产品中获取类别名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆