Created
August 13, 2020 20:28
-
-
Save pablo-sg-pacheco/d0096e7feae17665ce3a057d6b744e2b to your computer and use it in GitHub Desktop.
Change WooCommerce Coupon amount on the fly (programmatically)
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
<?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