duanfengtuo6012 2014-08-09 14:01
浏览 62
已采纳

设置WooCommerce产品的摘录长度

I am trying to set the excerpt length for WooCommerce products but the following code does not work as expected:

<?php
    function custom_excerpt_length($length) {
        global $post;
        if ($post->post_type == 'post')
            return 10;
        else if ($post->post_type == 'product')
            return 10;
        else if ($post->post_type == 'product_variation')
            return 10;
    }
    add_filter('excerpt_length', 'custom_excerpt_length');
?>
  • 写回答

1条回答 默认 最新

  • dswsl2016 2014-08-09 14:50
    关注

    In the woocommerce/templates/single-product/short-description.php folder there is the following code.

    <?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ) ?>
    

    Replace the above code with the following code*.

    <?php $excerpt = apply_filters( 'woocommerce_short_description', $post->post_excerpt );
        echo substr($length,0, 10);
    ?>
    

    Changing 10, with a length you require.

    It is advised to copy that file to yourtheme/woocommerce/templates/single-product/short-description.php, otherwise when/if you update woocommerce your changes will be overwritten.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答