Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the discount code set on the level object when set #3247

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion includes/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function pmpro_save_checkout_data_to_order( $order ) {
update_pmpro_membership_order_meta( $order->id, 'checkout_level', $pmpro_level_arr );

// Save the discount code.
// @TODO: Remove this in v4.0. Discount codes should be set on the level object.
update_pmpro_membership_order_meta( $order->id, 'checkout_discount_code', $discount_code );

// Save any files that were uploaded.
Expand Down Expand Up @@ -156,6 +157,7 @@ function pmpro_pull_checkout_data_from_order( $order ) {
$pmpro_level = (object) $checkout_level_arr;

// Set $discount_code_id.
// @TODO: Remove this in v4.0. Discount codes should be set on the level object.
$discount_code = get_pmpro_membership_order_meta( $order->id, 'checkout_discount_code', true );

// Set $_REQUEST.
Expand Down Expand Up @@ -218,7 +220,13 @@ function pmpro_complete_checkout( $order ) {
$enddate = apply_filters( "pmpro_checkout_end_date", $enddate, $order->user_id, $pmpro_level, $startdate );

// If we have a discount code but not the ID, get the ID.
if ( ! empty( $discount_code ) && empty( $discount_code_id ) ) {
if ( ! empty( $pmpro_level->discount_code ) ) {
$discount_code = $pmpro_level->discount_code;
$discount_code_id = empty( $pmpro_level->code_id ) ? $wpdb->get_var( "SELECT id FROM $wpdb->pmpro_discount_codes WHERE code = '" . esc_sql( $discount_code ) . "' LIMIT 1" ) : $pmpro_level->code_id;
} elseif ( ! empty( $discount_code ) && empty( $discount_code_id ) ) {
// Throw a doing it wrong warning. If a discount code is being used, it should be set on the level.
// @TODO: Remove this in v4.0 along with references to the discount code globals. Discount codes should be set on the level object.
_doing_it_wrong( __FUNCTION__, __( 'Discount codes should be set on the $pmpro_level object.', 'paid-memberships-pro' ), 'TBD' );
$discount_code_id = $wpdb->get_var( "SELECT id FROM $wpdb->pmpro_discount_codes WHERE code = '" . esc_sql( $discount_code ) . "' LIMIT 1" );
}

Expand Down