首页 > 解决方案 > 使用产品表插件在产品名称 WooCommerce 下显示产品标签

问题描述

我正在使用 WooCommerce 并希望在产品标题下显示产品标签。我使用了这段代码并稍作修改,它可以在产品页面、商店页面和其他地方正常工作:

add_filter( 'the_title', 'show_tags_under_product_name', 10, 2 );
function show_tags_under_product_name( $title, $post_id ) {

    if ( get_post_type( $post_id ) != 'product' )
        return $title;

    if ( is_shop() || is_product_tag() || is_product_category() )
        return $title;

    $terms = wp_get_post_terms( $post_id, 'product_tag' );
    $term = reset( $terms );

    if ( !empty( $term->name ) )
        $title .= '<br><div class="product-tags">'. $term->name .'</div>';

    return $title;
}

但是,它不会显示在订购页面上,我使用此插件在表格中显示所有产品并允许单页订购,多个产品到购物车 – WooCommerce 产品表

这是该插件中显示表格的代码的一部分:

<?php do_action( 'mpc_table_columns', $atts ); ?>
        <tbody><?php
        if( isset( $products ) && count( $products ) > 0 ){
            foreach( $products as $product_post ){
                $product = wc_get_product( $product_post->ID );
                do_action( 'mpc_row_loader', $product, $atts );
            }
        }

我可以修改第一个片段以使其显示在产品表上,还是需要修改插件中的代码?

标签: phpwordpresswoocommerce

解决方案


推荐阅读