Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1421429

    Tristan A
    Participant

    Hi there!

    I have been going through this thread https://community.theme.co/forums/topic/woocommerce-displaying-inventory-amount-and-short-description-on-shop-page/ and took the very first code section on that page:

    //Add excerpt to archive pages
    
    add_action( 'woocommerce_after_shop_loop_item_title', 'output_product_excerpt', 35 );
    
    function output_product_excerpt() {
    global $post;
    echo $post->post_excerpt;
    }
    
    //Add stock status to archive pages
    
    function envy_stock_catalog() {
        global $product;
        if ( $product->is_in_stock() ) {
            echo '<div class="stock" >' . $product->get_stock_quantity() . __( ' in stock', 'envy' ) . '</div>';
        } else {
            echo '<div class="out-of-stock" >' . __( 'out of stock', 'envy' ) . '</div>';
        }
    }
    add_action( 'woocommerce_after_shop_loop_item_title', 'envy_stock_catalog' );

    It works fine, except i would like to restrict the excerpt to a limited number of characters…. How should I do that?

    Kind regards, Tristan

    #1421432

    Tristan A
    Participant
    This reply has been marked as private.
    #1421441

    Tristan A
    Participant

    Please note also that with .woocommerce .entry-wrap {box-shadow: none;} i have been able to remove the box shadow sitting between the product title/price and description.

    However, I would also like to manipulate the text of that short description: Reduce the font size, and add some padding, so the text doesn’t hit the borders of the .entry-product div?

    #1421478

    Paul R
    Moderator

    Hi,

    You can change your code to this.

    
    //Add excerpt to archive pages
    
    add_action( 'woocommerce_after_shop_loop_item_title', 'output_product_excerpt', 35 );
    
    function output_product_excerpt() {
       global $post;
       echo word_limiter($post->post_excerpt,20);
    }
    

    Change 20 to adjust the excerpt length.

    Then to adjust the font size, you can add this in Custom > Edit Global CSS

    
    .archive.woocommerce .product .entry-product {
         font-size: 14px;
         padding:10px 10px 10px;
    }
    

    Hope that helps.

    #1421498

    Tristan A
    Participant

    Thanks, but that code doesn’t work.

    When i replace `//Add excerpt to archive pages

    add_action( ‘woocommerce_after_shop_loop_item_title’, ‘output_product_excerpt’, 35 );

    function output_product_excerpt() {
    global $post;
    echo $post->post_excerpt;
    }`

    with

    //Add excerpt to archive pages
    
    add_action( 'woocommerce_after_shop_loop_item_title', 'output_product_excerpt', 35 );
    
    function output_product_excerpt() {
       global $post;
       echo word_limiter($post->post_excerpt,20);
    }

    the shop page only displays one product, and without the description…?

    #1421506

    Tristan A
    Participant

    Also please notice that

    .archive.woocommerce .product .entry-product {
         font-size: 14px;
         padding:10px 10px 10px;
    }

    changes the padding of the entire .entry-product, which is not what i intent to do. It increases the spacing between the products on the shoppage.

    Rather, i would like to have some white space around the description text, but not alter the size of the .entry product. I hope i explained it better.

    #1421642

    Paul R
    Moderator

    Hi,

    In that case, you may change the php code to this.

    
    //Add excerpt to archive pages
    
    add_action( 'woocommerce_after_shop_loop_item_title', 'output_product_excerpt', 20 );
    
    function output_product_excerpt() {
    global $post;
    echo '<div class="my-excerpt">'.wp_trim_words($post->post_excerpt,20).'</div>';
    }
    
    

    Then change the css code to this.

    
    .my-excerpt {
    padding:20px;
    }
    
    

    Hope that helps