Last active
January 18, 2025 11:16
-
-
Save assoscoupa/5fbbae8510681b761785c26226bbb732 to your computer and use it in GitHub Desktop.
Add Read More in WooCommerce Category Description
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_after_main_content', 'qwerty_gr_woocommerce_after_main_content' ); | |
function qwerty_gr_woocommerce_after_main_content() { | |
if ( is_product_category() ){ | |
wc_enqueue_js(' | |
var show_char = 60; | |
var ellipses = "... "; | |
var content = $(".term-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\'>Read more</a></span><span class=\'truncated\' style=\'display:none\'>" + b + "</span>"; | |
$(".term-description").html(html); | |
} | |
$(".read-more").click(function(e) { | |
e.preventDefault(); | |
$(".term-description .truncated").toggle(); | |
}); | |
'); | |
} | |
} |
FYI the Alternative Method is very clean and has the read less button, but unfortunately it breaks Ajax sorting and add to cart on woocomerce pages (did on my theme)
Is there a way to add read less to the '[Add_Read_More_in_WooCommerce_Category_Description.php]'?
Thanks,
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.