Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Something like this:

    add_action( 'woocommerce_after_shop_loop_item_title', 'output_product_excerpt', 35 );
    
    function output_product_excerpt() {
    global $post;
    echo $post->post_excerpt;
    }

    This outputs the full excerpt. You can adjust length etc from there using PHP code.

    Thread Starter macaulayken

    (@macaulayken)

    Hi Mike,

    Much thanks for the help – finally worked.

    Having a little trouble with setting excerpt lengths though…
    Not a php coder – strictly copy & paste.

    Any additional help appreciated.

    Thanks,
    Ken

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Thread Starter macaulayken

    (@macaulayken)

    Thanks for the pointer.
    Time to do a bit of learning…
    Regards,
    Ken

    Hi,where to put the code to show short description?..

    Its ok.. its worked after put in on function.php ??

    This is what i was looking for tnx

    Hi

    I found a practical solution to cut the length.
    This may be helpful for others:

    First a function to limit the text length:

    function limit_text($text, $limit) {
          if (str_word_count($text, 0) > $limit) {
              $words = str_word_count($text, 2);
              $pos = array_keys($words);
              $text = substr($text, 0, $pos[$limit]) . '...';
          }
          return $text;
        }

    Then the actual action hook:

    add_action( 'woocommerce_after_shop_loop_item_title', 'output_product_excerpt', 35 );
    
    	function output_product_excerpt() {
    	global $post;
    	//assign variable $rest and call the function limit_text with value as shown
            //in this example 10 words is the maximum
    	$rest = limit_text($post->post_excerpt,10);
            //render $rest
    	echo '<p>' . $rest .'</p><i><a href="'. get_permalink( get_the_ID() ) . '">more</a></i>';
    }

    I tested the code and it seems to work. Cutting the text by words makes more sense
    than subtracting single characters ($rest = substr(“abcdef”, 0, -1); // returns “abcde”).
    Note: limit_text() needn’t be altered at all.

    Compared with the simple method to limit an excerpt in wordpress, it is a little more work in woocommerce.

    regards
    theo

    • This reply was modified 7 years, 11 months ago by timholz.

    Thanks, its a nice script and very useful

    reggiescottjr

    (@reggiescottjrverizonnet)

    @mikejolley

    Awesome man! Thanks so much. How would I add a custom class to style the short description? Right now when it displays on my main shop page I need to finesse the style without effecting how it appears on the product page. Any info would help.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘show a short description in shop & category pages’ is closed to new replies.