Skip to content

Instantly share code, notes, and snippets.

@pablo-sg-pacheco
Created August 13, 2020 20:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablo-sg-pacheco/d0096e7feae17665ce3a057d6b744e2b to your computer and use it in GitHub Desktop.
Save pablo-sg-pacheco/d0096e7feae17665ce3a057d6b744e2b to your computer and use it in GitHub Desktop.
Change WooCommerce Coupon amount on the fly (programmatically)
<?php
add_filter('woocommerce_get_shop_coupon_data', 'fix_wc_coupon_discount_amount', 10, 3);
function fix_wc_coupon_discount_amount( $false, $data, $coupon ) {
if (
'yes' !== get_option( 'wcj_multicurrency_compatibility_wc_coupons', 'no' )
|| is_admin()
|| empty( $coupon_id = wc_get_coupon_id_by_code( $data ) )
|| 'fixed_cart' != get_post_meta( $coupon_id, 'discount_type', true )
) {
return $false;
}
$current_coupon_amount = get_post_meta( $coupon_id, 'coupon_amount', true );
$coupon->set_amount( $current_coupon_amount * 3 );
return $coupon;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment