php - 使用产品表插件在产品名称 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 );
}
}
我可以修改第一个片段以使其显示在产品表上,还是需要修改插件中的代码?
解决方案
推荐阅读
- python - 如何获取单选按钮来更新直方图 Matplotlib Python
- reactjs - 如何将ant design类组件转换为功能组件
- java - 使用 Jsoup 将数据从网页解析到 Android 应用
- python - 可以导入pytorch但不能导入torch
- angular - Angular 2方式绑定组件
- python - 使用 Selenium 和 Python 从 svg 标签中的 g 标签获取文本
- javascript - 在evennode.com的真实主机上使用mongodb的问题
- excel - 如何改进将 14 列月薪表转换为 4 列数据集的 VBA 代码
- javascript - 如何在 DeviceMotionEvent javascript 中设置间隔
- sqlite - 如何将片假名添加到 SQLite3?