Support » Plugin: WooCommerce » Entry-Summary / excerpt html

  • Resolved outfitty

    (@outfitty)


    Hey guys,

    when I want to add html to the entry-Summary / excerpt of a product, it will only be shown at the single-product page.

    But I want to have it in the overview of the shop on the homepage, too.

    Is there any option?

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @outfitty,

    Try below code in child theme or main theme functions.php and let me know if it’s the same what you’re looking for.

    /* ADD EXCERPT UNDER PRODUCT PAGE */
    add_action( 'woocommerce_after_shop_loop_item_title', 'add_short_description', 9 );
    function add_short_description() {
         echo '<span class="title-description">' . the_excerpt() . '</span>';
    }
    Thread Starter outfitty

    (@outfitty)

    Thanks.

    But it doesn’t works.

    It is still text.
    When i add a color or bold its only on the product page – nowhere else.

    Any other idea?

    Can you please try below code and see if you’re getting the same result as what you’re looking for.

    
    /* Allow HTML Tags in WordPress Excerpt */
    if ( ! function_exists( 'wpse_custom_wp_trim_excerpt' ) ) : 
    	function wpse_custom_wp_trim_excerpt( $wpse_excerpt ) {
    	$raw_excerpt = $wpse_excerpt;
    		if ( '' == $wpse_excerpt ) {
    			$wpse_excerpt = get_the_content( '' );
    			$wpse_excerpt = strip_shortcodes( $wpse_excerpt );
    			$wpse_excerpt = apply_filters( 'the_content', $wpse_excerpt );
    			$wpse_excerpt = str_replace( ']]>', ']]>', $wpse_excerpt );
    			//Set the excerpt word count and only break after sentence is complete.
    			$excerpt_word_count = 75;
    			$excerpt_length = apply_filters( 'excerpt_length', $excerpt_word_count ); 
    			$tokens = array();
    			$excerptOutput = '';
    			$count = 0;
    			// Divide the string into tokens; HTML tags, or words, followed by any whitespace
    			preg_match_all( '/(<[^>]+>|[^<>\s]+)\s*/u', $wpse_excerpt, $tokens );
    			foreach ( $tokens[0] as $token ) { 
    				if ( $count >= $excerpt_length && preg_match( '/[\,\;\?\.\!]\s*$/uS', $token ) ) { 
    					// Limit reached, continue until , ; ? . or ! occur at the end
    					$excerptOutput .= trim( $token );
    					break;
    				}
    				// Add words to complete sentence
    				$count++;
    				// Append what's left of the token
    				$excerptOutput .= $token;
    			}
    			$wpse_excerpt = trim( force_balance_tags( $excerptOutput ) );
    				$excerpt_end = ' <a href="'. esc_url( get_permalink() ) . '">' . '&nbsp;&raquo;&nbsp;' . sprintf( __( 'Read more about: %s &nbsp;&raquo;', 'wpse' ), get_the_title() ) . '</a>'; 
    				$excerpt_more = apply_filters( 'excerpt_more', ' ' . $excerpt_end ); 
    				$wpse_excerpt .= $excerpt_more; /* Add read more in new paragraph */
    			return $wpse_excerpt;   
    		}
    		return apply_filters( 'wpse_custom_wp_trim_excerpt', $wpse_excerpt, $raw_excerpt );
    	}
    endif; 
    remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
    add_filter( 'get_the_excerpt', 'wpse_custom_wp_trim_excerpt' ); 
    Thread Starter outfitty

    (@outfitty)

    Thanks, but it still changes nothing.

    The div, which is correct with html is woocommerce-product-details__short-description
    On the product & archives page it’s the div entry-summary

    Thread Starter outfitty

    (@outfitty)

    I am no php freak but I solved it by myself.

    After
    <?php if (isset($options[$product_template . '_show_content']) && $options[$product_template . '_show_content'] != 'hidden'): ?>

    I inserted:

    <?php if ($options[$product_template . '_show_content'] == 'excerpt') : ?>
                    <?php
    if ( ! defined( 'ABSPATH' ) ) {
                    exit;
    }
    global $post;
    $short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );
    if ( ! $short_description ) {
                    return;
    }
    ?>
      <?php endif; ?>

    But is this a smart solution?
    Or is there a better one?

    Plugin Support AW a11n

    (@slash1andy)

    Automattic Happiness Engineer

    Glad that this is sorted, marking as resolved.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Entry-Summary / excerpt html’ is closed to new replies.