Created
September 8, 2014 22:02
-
-
Save dancameron/02da9feae311ed673497 to your computer and use it in GitHub Desktop.
EDD Recurring Payments & Discounts
This file contains 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 | |
function modify_edd_get_discount_amount( $amount, $code_id ) { | |
// Download requirements | |
$download_id = 49; | |
// Coupon code filtered | |
$dcodes = array( 'YOUDONTHINKIKNOW', 'WHATYOURETRYINGTODO?', 'NICETRY!!' ); | |
// Filter only the discount code above | |
$code = edd_get_discount_code( $code_id ); | |
if ( in_array( $code, $dcodes ) ) { | |
// Check cart of requirements before filtering amount | |
$cart_items = edd_get_cart_contents(); | |
$cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; | |
if ( is_array( $cart_ids ) ) { | |
// check to make sure the cart has the download this discount applies to | |
if ( in_array( $download_id, $cart_ids ) ) { | |
// Find the $cart_items key of the download | |
$key = array_search( $download_id, $cart_ids ); | |
// Check to make sure there's a variable price | |
if ( isset( $cart_items[$key]['options']['price_id'] ) ) { | |
// Each variable price will have it's own discount. | |
switch ( $cart_items[$key]['options']['price_id'] ) { | |
case 0: // freelancer mo | |
$amount = 9.00; | |
break; | |
case 1: // freelancer yr | |
$amount = 20.00; | |
break; | |
case 2: // biz mo | |
$amount = 15.00; | |
break; | |
case 3: // biz yr | |
$amount = 35.00; | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
} | |
} | |
return (float) $amount; | |
} | |
add_filter( 'edd_get_discount_amount', 'modify_edd_get_discount_amount', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment