Last active
June 4, 2021 11:06
-
-
Save assoscoupa/5fbbae8510681b761785c26226bbb732 to your computer and use it in GitHub Desktop.
Add Read More in WooCommerce Category Description
This file contains 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(); | |
}); | |
'); | |
} | |
} |
Author
assoscoupa
commented
Jun 4, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment