2016-06-01 2 views
1

関連商品リストの短い説明の制限を設定する必要があります。関連商品リストの簡略説明の制限を設定してください

私は、フィルタを使用して、製品一覧ページのためにこれを行っている:

function my_filter_woocommerce_short_description($post_excerpt) { 
 

 
    if(is_product()){ 
 

 

 
    }else{ 
 
      $post_excerpt = get_the_content(); 
 
$post_excerpt = preg_replace(" (\[.*?\])",'',$post_excerpt); 
 
$post_excerpt = strip_shortcodes($post_excerpt); 
 
$post_excerpt = strip_tags($post_excerpt); 
 
$post_excerpt = substr($post_excerpt, 0, 265); 
 
$post_excerpt = substr($post_excerpt, 0, strripos($post_excerpt, " ")); 
 
$post_excerpt = trim(preg_replace('/\s+/', ' ', $post_excerpt)); 
 
$post_excerpt = $post_excerpt.'... <a href="'.get_permalink($product_id).'">more</a>'; 
 

 
      //$post_excerpt=substr($post_excerpt , 0 ,265); 
 
     return $post_excerpt.'...'; 
 
    } 
 
} 
 
add_filter('woocommerce_short_description','my_filter_woocommerce_short_description',10, 2);

を私はこのフィルタの内側に、製品ページに完全な短い説明を表示する必要があるが、私はif is製品を作成しました。 問題は製品ページ内です。製品リストページに表示されているので、私は短く表示する必要がある関連製品のリストもあります。

どうすればいいですか?

は、あなたの代わりに使用したフィルタの

答えて

2

、アクション「woocommerce_after_shop_loop_item_title」

add_action('woocommerce_after_shop_loop_item_title','short_description_content', 5); 

function short_description_content(){ 
    //code for short description content 
} 

この方法では、あなたはそれが単一の製品または製品のリストがあるかどうかを確認する必要はありません。この方法を試してみてくださいありがとうございました。あなたが言ったように、関連する製品のリストに簡単な説明が表示さだけで上記の関数で

function short_description_content(){ 
    the_excerpt(); 
} 
+0

「をthe_excerpt」を追加しかし、問題は、私は、製品ページに抜粋を行う必要があるということですが、それに

関連商品リストのみ –

+0

これは難しいことではありません。あなたが言ったように、関連する製品リストに簡単な説明を表示するには、上記の関数に 'the_excerpt' –

関連する問題