Skip to content

Instantly share code, notes, and snippets.

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 mohsinworld/28c3d2c98dbcb2033d9651fd527e916b to your computer and use it in GitHub Desktop.
Save mohsinworld/28c3d2c98dbcb2033d9651fd527e916b to your computer and use it in GitHub Desktop.
Code Snippet
// Automatically shortens WooCommerce product titles on the main shop, category, and tag pages
// to a set number of characters
function short_woocommerce_product_titles_chars( $title, $id ) {
if ( ( is_shop() || is_product_tag() || is_product_category() ) && get_post_type( $id ) === 'product' ) {
// Kicks in if the product title is longer than 60 characters
if ( strlen( $title ) > 40) {
// Shortens it to 60 characters and adds ellipsis at the end
return substr( $title, 0, 40 ) . '...';
}
}
return $title;
}
add_filter( 'the_title', 'short_woocommerce_product_titles_chars', 10, 2 );
=============================================================
Custom CSS
.woocommerce-loop-product__title {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
=============================================================
Another way for Astra floating add to cart
.ast-sticky-add-to-cart-title {white-space:pre; overflow:hidden; text-overflow:ellipsis; width:660px;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment