WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Short description below product (22 posts)

  1. webow
    Member
    Posted 1 year ago #

    How to add short description below products in shop page where are listed products?

    http://wordpress.org/extend/plugins/woocommerce/

  2. glamj
    Member
    Posted 1 year ago #

    im looking for this too ! somebody know. .??

  3. bheadrick
    Member
    Posted 1 year ago #

    Here's the solution I came up with. This goes in your theme's functions.php:

    add_action('add_meta_boxes', 'product_title_desc_box');
    add_action('save_post', 'product_title_desc_save', 1, 2);
    
    function product_title_desc_box(){
        add_meta_box('product_title_desc_box', 'Product Title Description', 'product_title_desc_form', 'product','side', 'core');
        wp_nonce_field( basename( __FILE__ ), 'smashing_post_class_nonce' );
    }
    function product_title_desc_form($post){
        wp_nonce_field( basename( __FILE__ ), 'product_title_description_nonce' );
        $value = get_post_meta($post->ID, 'title-description', true);
        ?> <p><label for="title-description">Enter a short description to be displayed below the title in the catalog pages</label>
            <br />
            <input type="text" name="title-description" id="title-description" value="<?php echo $value ; ?>"/>
        </p>
        <?php
    }
    
    function product_title_desc_save($post_id, $post ){
        if(!isset( $_POST['title-description']) || !wp_verify_nonce($_POST['product_title_description_nonce'], basename(__FILE__)))
                    {
            return $post_id;
                    }
                     $post_type = get_post_type_object( $post->post_type );
    
        /* Check if the current user has permission to edit the post. */
        if ( !current_user_can( $post_type->cap->edit_post, $post_id ) )
            return $post_id;
    
                    $description = $_POST['title-description'] ;
                     update_post_meta( $post_id, 'title-description', $description);
    
    }
    add_action('woocommerce_after_shop_loop_item_title','add_title_description',9);
    function add_title_description(){
      echo get_post_meta($product->id, 'title-description', true)? '<span class="title-description">' . get_post_meta($product->id, 'title-description', true) . '</span><br />' : '';
    }
  4. bheadrick
    Member
    Posted 1 year ago #

    you'll find a new "Product Title Description" field on your post edit screen

  5. webow
    Member
    Posted 1 year ago #

    I don't see "Product Title Description". Upload same screenshot...

  6. travhoog
    Member
    Posted 1 year ago #

    I would be interested if anyone knows how to apply this to the output of widgets, like the Best Sellers widget. I have it on my redesigned company site, and left space for a short except.

    http://184.154.165.114/~cusackef/cusackmusic.com/

  7. bheadrick
    Member
    Posted 1 year ago #

    There's no clean way to do this as that widget doesn't use any filter or action hooks and no template files

    Temporarily, you could modify woocommerce/widgets/widget-best_sellers.php
    by replacing this line:

    </a> <?php echo $product->get_price_html(); ?></li>

    with this:

    </a> <?php echo get_post_meta($product->id, 'title-description', true)? '<span class="title-description">' . get_post_meta($product->id, 'title-description', true) . '</span><br />' : '';
    
     echo $product->get_price_html(); ?></li>

    but it's probably a better idea to create a plugin to essentially duplicate this widget with your customizations

  8. travhoog
    Member
    Posted 1 year ago #

    Yeah, I thought that might be the case. I did something similar to your temporary solution and lost my changes on the last update. Stupid newb mistake. Live and learn I guess. Thanks.

  9. Solar-Plexus
    Member
    Posted 1 year ago #

    Same here, I see no "Product Title Description" field on the post edit screen! ;(

  10. cjubewa
    Member
    Posted 1 year ago #

    I after paste the your code i can see the "Product Title Description" , but after saving the product i can't see any desc after title....i paste the code at the end of the function.php before the php close tag "?>"..
    why i can see the "product title description" but it didn't work...
    I cried when I saw the description field, because they are many weeks that I try to solve the problem ....but didn't work...Why in your opinion?
    Sorry for my english...

  11. bheadrick
    Member
    Posted 1 year ago #

    @cjubewa:
    that chunk of code only adds a field for a postmeta value. You also have to modify something else to display that value.

    where do you want to display it? category/archive pages? single product page? both? something else?

  12. cjubewa
    Member
    Posted 1 year ago #

    Hi !!! I want to display it in shop page (listing page) before the add to cart button...This for give more information before the client click the product to enter in the single product page...Thanks for your answer !!

  13. cjubewa
    Member
    Posted 1 year ago #

    Hi , can you give me an example how to call that value in shop page? Thanks!

  14. cjubewa
    Member
    Posted 1 year ago #

    If i paste in content-product.php this code i can see short description in te right place..
    what is the name of the value that I have to call to see the text that I wrote in the box that I have created with your code?

    code that call short description:

    <?php echo $product->get_sku(); ?>

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

    Hope you help me i want to use your solution....

  15. param sheoran
    Member
    Posted 11 months ago #

    hey i used the code below to show product description short but it shows the complete descripion no restricting the description to few words. its showing all the content of product description but i want to show only few text and then view more link.
    below is code help me soon if you can.

    "><h3><?php the_title(); ?></h3>

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

    ">Read More >>

    this code i used but show full i need to show few and then full on view more.

  16. Joshua David Nelson
    Member
    Posted 11 months ago #

    There is a "Product Short Description" on the product edit page, which is really just the excerpt for that custom post type. Here's how to add it to the list page:

    add_action( 'woocommerce_after_shop_loop_item_title', 'my_add_short_description', 9 );
    function my_add_short_description() {
    	  echo '<span class="title-description">' . the_excerpt() . '</span><br />';
    }
  17. liziziv
    Member
    Posted 11 months ago #

    Joshua hi
    do you put it on the content product.php page?

  18. Joshua David Nelson
    Member
    Posted 10 months ago #

    liziziv,

    No, you place that in your (child) theme's function.php file. Don't ever edit any files in a plugin or your parent theme, because updates will wipe out your custom code.

    Hope that helps!

  19. eyncnm
    Member
    Posted 8 months ago #

    Thanks Joshua, this works!

  20. badmanmedia
    Member
    Posted 7 months ago #

    Hi Joshua,
    I can't seem to get this method working, however, I wander if it's due to my theme not being a Woocomerce supporting theme.

    Any Ideas?

  21. bheadrick
    Member
    Posted 7 months ago #

    you can't echo the_excerpt()
    you need to replace that with get_the_excerpt()

    otherwise, looks like it should work okay

  22. Joshua David Nelson
    Member
    Posted 7 months ago #

    bheadrick, thanks for the catch.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.