【发布时间】:2018-03-28 01:39:17
【问题描述】:
我正在尝试在 Woocommerce 上的产品名称下方添加产品标签。我在这里找到了类似的代码并尝试对其进行自定义,但无法正常工作。
/**
* Add product's brand name to product's name.
*/
add_filter( 'the_title', 'mycode_add_brand_to_product_title', 10, 2 );
function mycode_add_brand_to_product_title( $title, $id ) {
$type = get_post_type( $id );
if ( $type != 'product' ) { return $title; }
$terms = wc_get_product_terms( $post->ID, 'product_tag' );
$brand = array_shift( $terms );
if ( !empty( $brand ) ) {
$title = $brand . ' ' . $title;
}
return $title;
}
有人可以帮忙吗?
这是我想要实现的预览:
【问题讨论】:
标签: php wordpress woocommerce product custom-taxonomy