Add Text under Single Product Short Description in Woocommerce

19,150

Solution 1

Update 2: There is 3 different ways, using hooks:

1) Adding your custom text at the end of the short description content, (not for variable products):

add_filter( 'woocommerce_short_description', 'add_text_after_excerpt_single_product', 20, 1 );
function add_text_after_excerpt_single_product( $post_excerpt ){
    if ( ! $short_description )
        return;

    // Your custom text
    $post_excerpt .= '<ul class="fancy-bullet-points red">
    <li>Current Delivery Times: Pink Equine - 4 - 6 Weeks, all other products 4 Weeks</li>
    </ul>';

    return $post_excerpt;
}

Important - For variable products:
I found that there is bug like in When using the filter woocommerce_short_descriptionthat is apparently also active for the product variation description, and it should not (as this is not documented in developers documentation)The solution is below:

2) Adding your custom text at the end of the short description content, for all product types:

add_action( 'woocommerce_single_product_summary', 'custom_single_product_summary', 2 );
function custom_single_product_summary(){
    global $product;

    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
    add_action( 'woocommerce_single_product_summary', 'custom_single_excerpt', 20 );
}

function custom_single_excerpt(){
    global $post, $product;

    $short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );

    if ( ! $short_description )
        return;

    // The custom text
    $custom_text = '<ul class="fancy-bullet-points red">
    <li>Current Delivery Times: Pink Equine - 4 - 6 Weeks, all other products 4 Weeks</li>
    </ul>';

    ?>
    <div class="woocommerce-product-details__short-description">
        <?php echo $short_description . $custom_text; // WPCS: XSS ok. ?>
    </div>
    <?php
}

3) Adding your custom text after the short description:

add_action( 'woocommerce_before_single_product', 'add_text_after_excerpt_single_product', 25 );
function add_text_after_excerpt_single_product(){
    global $product;

    // Output your custom text
    echo '<ul class="fancy-bullet-points red">
    <li>Current Delivery Times: Pink Equine - 4 - 6 Weeks, all other products 4 Weeks</li>
    </ul>';
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

Solution 2

This is the solution that worked for me:

add_filter('woocommerce_short_description','ts_add_text_short_descr');

function ts_add_text_short_descr($description){
    $text="Your text here";
    return $description.$text;
}
Share:
19,150
Denise Field
Author by

Denise Field

Updated on June 09, 2022

Comments

  • Denise Field
    Denise Field almost 2 years

    I want to add some Global Text immediately under the Product Short Description in Woo Commerce, before the product options.

    I can change the file directly, but of course as soon as it updates it gets over written.

    Is there another way of doing this?

  • Denise Field
    Denise Field about 6 years
    I want to put it at the end of the short description content. This is the text code<ul class="fancy-bullet-points red"> <li>Current Delivery Times: Pink Equine - 4 - 6 Weeks, all other products 4 Weeks</li></ul> code but on the function when I replace the custom text bit I get a parse error? Can you help.
  • Denise Field
    Denise Field about 6 years
    What it is I have a common UL LI and want to add a global one on the end, I have all the CSS set up so it works ok [link]pinkequine.com/pinknew/product/mattes-bespoke-ear-bonn‌​ets [link]
  • Denise Field
    Denise Field about 6 years
    I have installed it and thought it worked ok, however when you add all the options in so that you can Add to Cart, the custom text appears 2 times see here [link]pinkequine.com/product/mattes-bespoke-long-stud-girth its weird because the ear bonnets works ok but this doesnt for some reason
  • Denise Field
    Denise Field about 6 years
    maybe its something to do with the plugin I am using, it works fine initially but once all the options are selected I get a second copy come up in woocommerce-variation-description. I have accepted this as the answer as I think its the theme, but cant sort it out, thanks again
  • LoicTheAztec
    LoicTheAztec about 6 years
    @DeniseField Code Updated - I just found that there is bug like in woocommerce with the filter woocommerce_short_descriptionthat is apparently active in the product variation description, and it should not… So I have found a turn around, the 2nd way freshly added… This will work for you as expected… So you can clean all old comments please as this is completely solved now.
  • Denise Field
    Denise Field about 6 years
    I just wanted to thank you personally this solved the problem perfectly! Thank you for taking the time to sort this out, I wish I could upvote you even more than 1 point!