Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Last active June 5, 2025 03:44
Show Gist options
  • Save webtoffee-git/ff11cbf248859c82769eff9dead91f8d to your computer and use it in GitHub Desktop.
Save webtoffee-git/ff11cbf248859c82769eff9dead91f8d to your computer and use it in GitHub Desktop.
Code snippet to hide applied coupons and inapplicable coupons from display - By WebToffee (Smart Coupon Basic)
<?php>//Do not copy this line of code
add_filter( 'wt_smart_coupon_display_invalid_coupons', '__return_false' );
add_filter( 'wt_sc_alter_user_coupons', 'wbte_sc_remove_applied_coupons_from_user_coupons' );
if ( ! function_exists( 'wbte_sc_remove_applied_coupons_from_user_coupons' ) ) {
/**
* Remove applied coupons from user coupons list
*
* @param array $post_ids Array of coupon post IDs.
* @return array Modified array of coupon post IDs.
*/
function wbte_sc_remove_applied_coupons_from_user_coupons( $post_ids ) {
if ( is_null( WC()->cart ) ) {
return $post_ids;
}
$applied_coupon_ids = array_filter( array_map( 'wc_get_coupon_id_by_code', WC()->cart->get_applied_coupons() ) );
return array_diff( $post_ids, $applied_coupon_ids );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment