Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Progressive Pricing for EDD
<?php
function christmas_modify_edd_cart_contents( $cart ) {
// Download requirements
$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
$si_download_id = 49;
if ( in_array( $si_download_id, $cart_ids ) ) {
// Find the $cart_items key of the download
$key = array_search( $si_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 is 34.95 + 5/mo = 39.95
$fl_suf = 34.95-(39.95-current_time( 'd' ) );
// signup fee plus price is total paid now.
$cart[$key]['options']['recurring']['signup_fee'] = $fl_suf;
break;
case 1: // freelancer yr is 79.99
// Make the signup fee a negative number to discount the pay now price
$fly_suf = -80*(((25-current_time( 'd' ))*2)/100);
$cart[$key]['options']['recurring']['signup_fee'] = $fly_suf;
break;
case 2: // biz mo is 59.95 + 5/mo = 64.95
// signup fee plus price is total paid now.
$biz_suf = 59.95-(64.95-current_time( 'd' ) );
$cart[$key]['options']['recurring']['signup_fee'] = $biz_suf;
break;
case 3: // biz yr is 139.99
// Make the signup fee a negative number to discount the pay now price
$bizy_suf = -140*(((25-current_time( 'd' ))*2)/100);
$cart[$key]['options']['recurring']['signup_fee'] = $bizy_suf;
break;
default:
break;
}
}
}
// Help Scout Desk
$hsd_download_id = 1453;
if ( in_array( $hsd_download_id, $cart_ids ) ) {
// Find the $cart_items key of the download
$key = array_search( $hsd_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 1: // Single Site $69
// Make the signup fee a negative number to discount the pay now price
$ss_suf = -69*(((25-current_time( 'd' ))*2)/100);
// signup fee plus price is total paid now.
$cart[$key]['options']['recurring']['signup_fee'] = $ss_suf;
break;
case 2: // Multi Site $109
$ms_suf = -109*(((25-current_time( 'd' ))*2)/100);
$cart[$key]['options']['recurring']['signup_fee'] = $ms_suf;
break;
default:
break;
}
}
}
}
return $cart;
}
add_filter( 'edd_cart_contents', 'christmas_modify_edd_cart_contents' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.