2020年修订版 - 仍然适用于带有 WooCommerce 4.4.1 的 Wordpress 5.5.1
使用这个自定义函数挂钩the_title
过滤器挂钩将完成这项工作(替换管道字符|
by a <br>
在产品标题中):
add_filter( 'the_title', 'custom_product_title', 10, 2 );
function custom_product_title( $title, $post_id ){
$post_type = get_post_field( 'post_type', $post_id, true );
if( in_array( $post_type, array( 'product', 'product_variation') ) ) {
$title = str_replace( '|', '<br/>', $title ); // we replace "|" by "<br>"
}
return $title;
}
代码位于活动子主题(或主题)的 function.php 文件中或任何插件文件中。
代码在 Woocommerce 3+ 上进行了测试并且可以运行。
现在,您可以使用 WC 条件标签定位不同的产品页面,如下所示is_product()
, is_shop()
, is_product_category()
or is_product_tag()
(以及许多其他人)…