Skip to content

Commit

Permalink
Merge pull request #45 from dparker1005/fix-discount-code-delays
Browse files Browse the repository at this point in the history
Fixing discount code delays at checkout
  • Loading branch information
dparker1005 authored Aug 13, 2024
2 parents 28221b1 + d79218f commit 1872bd7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions pmpro-subscription-delays.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,24 @@ function pmprosd_pmpro_profile_start_date( $start_date, $order ) {
$subscription_delay = null;

// if a discount code is used, we default to the setting there
if ( ! empty( $order->discount_code ) ) {
global $wpdb;

// get code id
$code_id = $wpdb->get_var( "SELECT id FROM $wpdb->pmpro_discount_codes WHERE code = '" . esc_sql( $order->discount_code ) . "' LIMIT 1" );
if ( ! empty( $code_id ) ) {
// we have a code
$delays = pmpro_getDCSDs( $code_id );
if ( ! empty( $order->discount_code_id ) ) {
// The order has already been saved with a discount code.
$delays = pmpro_getDCSDs( $order->discount_code_id );
if ( ! empty( $delays[ $order->membership_id ] ) ) {
$subscription_delay = $delays[ $order->membership_id ];
}
} elseif( pmpro_is_checkout() && ! empty( $order->getMembershipLevelAtCheckout()->discount_code ) ) {
// We are at checekout and the discount code use has not been added to the order yet.
$discount_code = $order->getMembershipLevelAtCheckout()->discount_code;
$code_obj = new PMPro_Discount_Code( $discount_code );
if ( ! empty( $code_obj->id ) ) {
$delays = pmpro_getDCSDs( $code_obj->id );
if ( ! empty( $delays[ $order->membership_id ] ) ) {
$subscription_delay = $delays[ $order->membership_id ];
}
}
} else {
// No discount code, so we default to the setting on the level.
$subscription_delay = get_option( 'pmpro_subscription_delay_' . $order->membership_id, '' );
}

Expand Down

0 comments on commit 1872bd7

Please sign in to comment.