Created
March 23, 2021 22:51
-
-
Save WillBrubaker/df9a83e931d560788c3a0a4502e059e4 to your computer and use it in GitHub Desktop.
use one coupon code for both recurring % discount and sign-up fee % discount for WooCommerce Subscriptions
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
// not sure what to do with this code snippet? See https://www.thathandsomebeardedguy.com/what-do-i-do-with-these-code-snippets/ | |
// BTC Donations to: bc1qc2s60yct2aqza4r7ryweheepd8xa8wqpfgdhg3 | |
add_filter( 'woocommerce_coupon_get_discount_amount', 'handsome_bearded_guy_coupon_maybe_discount_sign_up_fee_too', 20, 5 ); | |
function handsome_bearded_guy_coupon_maybe_discount_sign_up_fee_too( $discount, $discounting_amount, $item, $single, $coupon ) { | |
if ( 'recurringandsignupdiscount' === $coupon->get_code() && is_callable( array( 'WC_Subscriptions_Product', 'get_sign_up_fee' ) ) ) { | |
$discounting_amount = WC_Subscriptions_Product::get_sign_up_fee( $item['data'] ); | |
$discount_percent = $coupon->get_amount() / 100; | |
$discount = $discounting_amount * $discount_percent; | |
} | |
return $discount; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment