Skip to content

Instantly share code, notes, and snippets.

@dancameron
Created September 8, 2014 22:25
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 dancameron/4d6166da27b86cab8a4b to your computer and use it in GitHub Desktop.
Save dancameron/4d6166da27b86cab8a4b to your computer and use it in GitHub Desktop.
EDD Recurring Payments & Discounts
<?php
function modify_edd_cart_contents( $cart ) {
$discounts = edd_get_cart_discounts();
if ( !$discounts ) {
return $cart;
}
$dcodes = array( 'YOUDONTHINKIKNOW', 'WHATYOURETRYINGTODO?', 'NICETRY!!' );
// Filter only the discount code above
if ( !array_intersect( $discounts, $dcodes ) ) {
return $cart;
}
// Download requirements
$download_id = 49;
$cart_ids = $cart ? wp_list_pluck( $cart, '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[$key]['options']['price_id'] ) ) {
// Each variable price will have it's own discount.
switch ( $cart[$key]['options']['price_id'] ) {
case 0: // freelancer mo
// signup fee plus price is total paid now.
$cart[$key]['options']['recurring']['signup_fee'] = 20.95;
break;
case 1: // freelancer yr
// Subtract the discount from the signup fee.
// which is set at zero
$cart[$key]['options']['recurring']['signup_fee'] = -20.00;
break;
case 2: // biz mo
// signup fee plus price is total paid now.
$cart[$key]['options']['recurring']['signup_fee'] = 35.95;
break;
case 3: // biz yr
// Subtract the discount from the signup fee.
// which is set at zero
$cart[$key]['options']['recurring']['signup_fee'] = -35.00;
break;
default:
break;
}
}
}
}
return $cart;
}
add_filter( 'edd_cart_contents', 'modify_edd_cart_contents' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment