Created
July 18, 2023 17:25
-
-
Save nielslange/43e0caa9d78a35ff060ce36f5c8a61c2 to your computer and use it in GitHub Desktop.
Coupons filter » coupons
This file contains hidden or 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
const { registerCheckoutFilters } = window.wc.blocksCheckout; | |
// Replace coupon label for matching coupon(s). | |
registerCheckoutFilters( 'example-extension', { | |
coupons: ( coupons ) => { | |
return coupons.map( ( coupon ) => { | |
// Regex to match autocoupon then unlimited undersores and numbers | |
if ( ! coupon.label.match( /autocoupon(?:_\d+)+/ ) ) { | |
return coupon; | |
} | |
return { | |
...coupon, | |
label: 'Automatic coupon', | |
}; | |
} ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment