• Resolved geaoger

    (@geaoger)


    Hi all,
    Recently I add showing the short description under product title on main Shop page by using following code:

    add_action( 'woocommerce_after_shop_loop_item_title', 'wc_add_short_description' );
    
    function wc_add_short_description() {
    	global $product;
    
    	?>
            <div itemprop="description">
                <?php echo substr( apply_filters( 'woocommerce_short_description', $product->post->post_excerpt ), 0,150 ); echo '...' ?>
            </div>
    	<?php
    }

    And it works fine, I can control description char length. But this short description become a hyperlink and it is the same color as title (red) not as usual text (black). I just need this short description to become text, not hyperlink.
    You can see how it looks like in the following screenshot: https://i.postimg.cc/vT2xtgw3/screenshot-2940.png
    If you have any question, feel free to ask, I will try to provide full answer.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Try inserting it after the link close action, which is at ‘woocommerce_after_shop_loop_item’, priority 5, but before add-to-cart which is at priority 10. So:

    add_action( 'woocommerce_after_shop_loop_item', 'wc_add_short_description', 8 );

    Plugin Support AW a11n

    (@slash1andy)

    Automattic Happiness Engineer

    @lorro gave a great answer, so going to leave that there for just a little bit before marking as resolved. This should be sorted.

    Thread Starter geaoger

    (@geaoger)

    @lorro Can you provide me more details about where should I paste your code?
    If I paste it in function.php I get short description duplicates – https://i.postimg.cc/SRj8Y7Yg/screenshot-2940.png

    Delete your line:
    add_action( 'woocommerce_after_shop_loop_item_title', 'wc_add_short_description' );

    This puts the short description inside the hyperlink – which you don’t want.

    Thread Starter geaoger

    (@geaoger)

    @lorro I deleted this line :
    add_action( 'woocommerce_after_shop_loop_item_title', 'wc_add_short_description' );

    And now only following code left:

    function wc_add_short_description() {
    	global $product;
    
    	?>
            <div itemprop="description">
                <?php echo substr( apply_filters( 'woocommerce_short_description', $product->post->post_excerpt ), 0,150 ); echo '...' ?>
            </div>
    	<?php
    }

    But after saving, I have not short description at all.

    You need this line:
    add_action( 'woocommerce_after_shop_loop_item', 'wc_add_short_description', 8 );

    Thread Starter geaoger

    (@geaoger)

    @lorro Thank you very much, now it works correctly. So I can close this topic as resolved.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Product Short Description on Shop Main Page become hyperlink’ is closed to new replies.