douerlin4366 2016-03-23 11:20
浏览 65
已采纳

限制主页和类别页面中的woocommerce产品简短描述

I have included product short description in my home and category pages by adding the following code to my child theme functions.php

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

Now I would like to limit the characters of product short description in the home and category pages.

Any help please??

More code and clarifications: My add_action is added to the following file woocommerce/includes/wc-template-hooks.php and here are the Product Loop Items.

add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );

add_action( 'woocommerce_before_subcategory', 'woocommerce_template_loop_category_link_open', 10 );
add_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title', 10 );
add_action( 'woocommerce_after_subcategory', 'woocommerce_template_loop_category_link_close', 10 );

add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );

everything is printed here: Mytheme/woocommerce/single-product.php and the code is

   <div class="container-inner">
        <?php do_action( 'woocommerce_before_shop_loop_item' ); ?>
        <div class="image-block">       
        <a href="<?php the_permalink(); ?>">        
            <?php
                /**
                 * woocommerce_before_shop_loop_item_title hook
                 *
                 * @hooked woocommerce_show_product_loop_sale_flash - 10
                 * @hooked woocommerce_template_loop_product_thumbnail - 10
                 */
                do_action( 'woocommerce_before_shop_loop_item_title' );
            ?></a>          
            <div class="product-block-hover"></div>

            </div>
<a href="<?php the_permalink(); ?>"><h3 class="product-name"><?php     the_title(); ?></h3></a>
            <?php
                /**
                 * woocommerce_after_shop_loop_item_title hook
                 *
                 * @hooked woocommerce_template_loop_rating - 5
                 * @hooked woocommerce_template_loop_price - 10 
                 */
                 do_action( 'woocommerce_after_shop_loop_item_title' );
            ?>                                      

        <?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
        </div>              
  • 写回答

4条回答 默认 最新

  • doujin8673 2016-03-23 19:47
    关注

    You can edit the lenght with the woocommerce_short_description filter, do something like this:

    add_filter('woocommerce_short_description','limit_short_descr');
    
    function limit_short_descr($description){
      return ($description > 140) ? substr($description, 0 , 140) : $description;
    }
    

    Also you can add a &hellip; after the text to make it look better.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭