Shorten product descriptions in Flatsome

rút gọn mô tả ngắn cho sản phẩm trong flatsome

Shorten product descriptions in Flatsome

Although it is a short description, many specific products have a rather long short description or for some reason you want to shorten the content of the short description, customers who want to see it all will click to see more to see. content.

Today Flatsomea-z will show you how to shorten the product description in Flatsome with just code.

Shorten product descriptions in Flatsome
Shorten product descriptions in Flatsome

Copy và paste this code into file functions.php 

add_action( 'woocommerce_after_single_product', 'woocommerce_short_description_truncate_read_more' );

function woocommerce_short_description_truncate_read_more() { 
wc_enqueue_js('
var show_char = 40;
var ellipses = "... ";
var content = $(".woocommerce-product-details__short-description").html();
if (content.length > show_char) {
var a = content.substr(0, show_char);
var b = content.substr(show_char - content.length);
var html = a + "<span class=\'truncated\'>" + ellipses + "<a class=\'read-more\'>Xem thêm</a></span><span class=\'truncated\' style=\'display:none\'>" + b + "</span>";
$(".woocommerce-product-details__short-description").html(html);
}
$(".read-more").click(function(e) {
e.preventDefault();
$(".woocommerce-product-details__short-description .truncated").toggle();
});
');
}

Replace 40 in the code with the number of characters you want to display!

Save and clear the cache and see the results! Good luck

3 thoughts on “Shorten product descriptions in Flatsome

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *