显示product_category标签在档案页面中的产品标题上方

发布于 2025-02-11 18:10:58 字数 794 浏览 2 评论 0原文

我有一家卖图片的商店。

每张图片都是由其艺术家进行了分类的。

我希望艺术家名称(子类别)在产品标题上方显示。

以下代码针对我想要的地方:

add_action( 'woocommerce_shop_loop_item_title','add_artist_name', 9);

function add_artist_name() {

        echo 'artiste name';
    
}

add_action( 'woocommerce_shop_loop_item_title','add_artist_name', 9);

function add_artist_name() {

    echo wc_get_product_category_list( $product->get_id(), ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '</span>' );

    
}

您能告诉我为什么添加该行不起作用,解决方案是什么?

此外,我只想显示子类别。

和往常一样,非常感谢。

I have a shop that sells pictures.

Each picture is sub-categorized by its artist.

I want the artist name (sub-category) to display above the product title.

The following code targets the place I want it to be :

add_action( 'woocommerce_shop_loop_item_title','add_artist_name', 9);

function add_artist_name() {

        echo 'artiste name';
    
}

enter image description here

I tried to duplicate the code that runs the category name on the single product page but it doesn't work and add bugs along the way.

add_action( 'woocommerce_shop_loop_item_title','add_artist_name', 9);

function add_artist_name() {

    echo wc_get_product_category_list( $product->get_id(), ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '</span>' );

    
}

Can you tell me why adding that line doesn't work and what is the fix ?

Furthermore, I would like only the subcategory to display.

As always, many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文