Skip to content

Instantly share code, notes, and snippets.

@tozbey
Created August 9, 2023 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tozbey/445939711418a28524abc0a62cf0a63d to your computer and use it in GitHub Desktop.
Save tozbey/445939711418a28524abc0a62cf0a63d to your computer and use it in GitHub Desktop.
Read more/less in WooCommerce product categories
<?php
/**
* Plugin Name: Read more/less
* Plugin URI: https://ozbey.se
* Description: Read more/less in WooCommerce product categories
* Version: 2
* Author: Tolga Ozbey
* Author URI: https://ozbey.se
* Requires at least: 5.6
* Requires PHP: 7.4
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
* WC requires at least: 5.0
* WC tested up to: 7.9
*/
add_filter( 'wp_footer', function ( ) {
if( is_product_category() && ! is_product_category( 'kampanj') ) {
?>
<style>
/* show more button */
.txt-mask {
-webkit-mask-image: -webkit-gradient(linear, 0% 60%, 0% 100%, from(black), to(rgba(0, 0, 0, 0)));
}
.showmore_trigger {
margin: 1.3em 0;
font-size: 12px;
text-transform: uppercase;
}
.showmore_trigger:hover {
margin: 1.3em 0;
font-size: 12px;
text-transform: uppercase;
cursor: pointer;
}
</style>
<script>
jQuery(document).ready(function () {
jQuery(".term-description").showMore({
speedDown: 300,
speedUp: 300,
height: "150px",
showText: "+ läs mer",
hideText: "- dölj"
});
});
(function (a) {
a.fn.showMore = function (b) {
var c = {
speedDown: 300,
speedUp: 300,
height: "265px",
showText: "Show",
hideText: "Hide"
};
var b = a.extend(c, b);
return this.each(function () {
var e = a(this),
d = e.height();
if (d > parseInt(b.height)) {
e.wrapInner('<div class="showmore_content txt-mask" />');
e.find(".showmore_content").css("height", b.height);
e.append(
'<div class="showmore_trigger"><span class="more">' +
b.showText +
'</span><span class="less" style="display:none;">' +
b.hideText +
"</span></div>"
);
e.find(".showmore_trigger").on("click", ".more", function () {
a(this).hide();
a(this).next().show();
a(this).parent().prev().animate({ height: d }, b.speedDown);
jQuery('.showmore_content').removeClass('txt-mask');
});
e.find(".showmore_trigger").on("click", ".less", function () {
a(this).hide();
a(this).prev().show();
a(this).parent().prev().animate({ height: b.height }, b.speedUp);
jQuery('.showmore_content').addClass('txt-mask');
});
}
});
};
})(jQuery);
</script>
<?php } });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment