最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to show only part of product name in category page - Wordpress with woocomerce

programmeradmin1浏览0评论

I want show only part of product name in my website, but show full name only in product page, Checkou, Cart and Invoice, like this:

Some one can Help me?

I want show only part of product name in my website, but show full name only in product page, Checkou, Cart and Invoice, like this:

Some one can Help me?

Share Improve this question asked Oct 13, 2019 at 20:32 Ademir OgliariAdemir Ogliari 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

I solved this problem with:

function hide_product_title_part( $title, $id ) {
  if ( ( is_front_page() || is_shop() || is_product_tag() || is_product_category() ) && get_post_type( $id ) === 'product' ) {
    if (strstr($title, ":")) {
      $new_title = explode(":", $title);
      return $new_title[1];
    } else {
      return $title;
    }
  } else {
    return $title;
  }
}
add_filter( 'the_title', 'hide_product_title_part', 10, 2 );
发布评论

评论列表(0)

  1. 暂无评论