Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Created December 31, 2024 10:30
Show Gist options
  • Save webtoffee-git/8d2ff70bcf7790d03bba39fe73824a93 to your computer and use it in GitHub Desktop.
Save webtoffee-git/8d2ff70bcf7790d03bba39fe73824a93 to your computer and use it in GitHub Desktop.
To hide the 'i' icon and display the coupon description in the coupon block, to remove the extra space taken by footer pagination when no pagination buttons exist, and to scroll up to the coupon applied message after applying, instead of scrolling down to the coupon form submission section, which is caused by a theme conflict - By WebToffee ( Sm…
<?php //Do not copy this line of code
add_action( 'wp_footer', function(){
?>
<style>
.wt-sc-coupon-description { float: left; background:none; opacity:0.7; line-height:22px; max-width:100%; font-size: 15px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
</style>
<script>
jQuery(document).ready(function($){
if( 0 >= $( '.wt_sc_pagination_next' ).length && 0 >= $( '.wt_sc_pagination_previous' ).length ){
$( '.wt_sc_pagination' ).hide();
}
$( '.wt_sc_coupon_desc_wrapper .info' ).hide();
$(document.body).on('applied_coupon', function () {
setTimeout(function () {
var notices = $('.woocommerce-notices-wrapper');
if (notices.length) {
$('html, body').animate({
scrollTop: notices.offset().top - 50
}, 500);
}
}, 200);
});
});
</script>
<?php
} );
add_filter( 'wt_sc_alter_final_coupon_template_html', function( $html, $coupon_style, $coupon_type, $coupon ) {
$coupon_description = $coupon->get_description();
if ( ! empty( $coupon_description ) ) {
$newDiv = '<div class="wt-sc-coupon-description">' . esc_html( $coupon_description ) . '</div>';
$html = wbte_sc_str_lreplace( '</div>', $newDiv . '</div>', $html );
}
return $html;
}, 10, 4 );
function wbte_sc_str_lreplace( $search, $replace, $subject ) {
$pos = strrpos( $subject, $search );
if ( false !== $pos ) {
$subject = substr_replace( $subject, $replace, $pos, strlen( $search ) );
}
return $subject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment