Issue adding text after short description on product pages Woocommerce [closed]
IT Nursery
May 21, 2022
0
I am trying to add some text after the short description on woocommerce. I have come up with the following add action but when I use it, it replaces the existing short description text.
Is there a way to add this after the existing short description without replacing?
function show_shipping_price() {
echo 'Order within <b>3 hours 27 minutes</b> to get it delivered for <b>only £1</b>';
}
add_filter( 'woocommerce_short_description', 'show_shipping_price' );
1 Answer 1
The Correct syntax for writing a add_filter
// Define the woocommerce_short_description callback
function filter_woocommerce_short_description( $post_excerpt ) {
// make filter magic happen here...
return $post_excerpt;
};
// add the filter
add_filter( 'woocommerce_short_description',filter_woocommerce_short_description',10, 1 );
Your code didn’t work well because the reason is that filter are used to modify the output.
Here is the function parameter you get the $post_excerpt parameter which will be displayed if not filters modify it.
If you want to achieve your purpose you can return you desired string with the $post_excerpt . You just need to modify the above code i mentioned with function like
function filter_woocommerce_short_description( $post_excerpt ) {
$your_msg='Order within <b>3 hours 27 minutes</b> to get it delivered for <b>only £1</b>';
return $post_excerpt.'<br>'.$your_msg;
}