Skip to content

Instantly share code, notes, and snippets.

@nielslange
Created July 18, 2023 17:25
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 nielslange/43e0caa9d78a35ff060ce36f5c8a61c2 to your computer and use it in GitHub Desktop.
Save nielslange/43e0caa9d78a35ff060ce36f5c8a61c2 to your computer and use it in GitHub Desktop.
Coupons filter » coupons
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