
-
AuthorPosts
-
February 17, 2019 at 10:03 pm #1068041
Hi,
I’m using this code to display short description on the shop page
add_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_single_excerpt’, 5);How can make it so that their is a limit as to how much short description shows on the shop page around 2 lines or something?
Thanks
ZakFebruary 18, 2019 at 3:18 pm #1068393Hey Zak,
Please share the woocommerce_template_single_excerpt function, it is the one that can be used to work with the excerpt length.
Best regards,
VictoriaFebruary 19, 2019 at 10:54 pm #1069144Hi Victoria,
Im assuming its this:
if ( ! function_exists( ‘woocommerce_template_single_excerpt’ ) ) {/**
* Output the product short description (excerpt).
*/
function woocommerce_template_single_excerpt() {
wc_get_template( ‘single-product/short-description.php’ );
}
}Apologies if I got the incorrect part.
FYI I added this code: add_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_single_excerpt’, 5); – in the child theme functions.php.Thanks
ZakFebruary 20, 2019 at 1:01 pm #1069434Hi Zak,
Here is the code you can put in your funtions.php
add_filter('woocommerce_short_description','avia_change_wc_description', 10, 1); function avia_change_wc_description($length) { $length = 100; return $length; }
If you need further assistance please let us know.
Best regards,
VictoriaFebruary 20, 2019 at 10:53 pm #1069724Hi Victoria,
Unfortunately, that does not work. It basically removes the text and instead says “100” under each product.
Thanks
ZakFebruary 23, 2019 at 9:15 pm #1070796Hi,
I’ve got the short description working using the following code:
add_filter(‘woocommerce_short_description’, ‘limit_woocommerce_short_description’, 10, 1);
function limit_woocommerce_short_description($post_excerpt){
if (!is_product()) {
$pieces = explode(” “, $post_excerpt);
$post_excerpt = implode(” “, array_splice($pieces, 0, 18));}
return $post_excerpt;
}Is it possible to add ‘…’ after the sentences?
Thanks
ZakFebruary 25, 2019 at 5:16 pm #1071359Hi Zak,
Glad you got it working for you and thank you for sharing your solution! :)
If you need further assistance please let us know.
Best regards,
VictoriaFebruary 25, 2019 at 11:22 pm #1071524Hi Victoria,
One last question.
Is it possible end the sentences with “…”? What code would I need to add to the current code?
Thanks
ZakiMarch 1, 2019 at 11:57 am #1073082Hi Zaki,
Try the return statement like this
return "{$post_excerpt}...";
If you need further assistance please let us know.
Best regards,
VictoriaMarch 1, 2019 at 12:08 pm #1073093Hi Victoria,
Thank you so much!
You can close this thread
Best Regards
Zak -
AuthorPosts
- The topic ‘Woocommerce short description limit’ is closed to new replies.