-
Notifications
You must be signed in to change notification settings - Fork 361
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
Prefix level and discount code parameters at checkout #2506
Prefix level and discount code parameters at checkout #2506
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the caching then merge. We will need to test a bunch, but this is all good otherwise.
includes/functions.php
Outdated
@@ -2323,56 +2323,72 @@ function pmpro_are_any_visible_levels() { | |||
*/ | |||
function pmpro_getLevelAtCheckout( $level_id = null, $discount_code = null ) { | |||
global $pmpro_level, $wpdb, $post; | |||
static $pmpro_getLevelAtCheckout_cache = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have to fix this to avoid warnings when the isset check is made.
Either a better check and setting up the array of arrays on demand. Or concat the level_id . ',' . $discount_code and hash that and use the hash for the cache key. And/or use the WP get/set cache functions.
if ( empty( $pmpro_level ) && ! empty( $level_id ) ) { | ||
$pmpro_level = $wpdb->get_row( "SELECT * FROM $wpdb->pmpro_membership_levels WHERE id = '" . esc_sql( $level_id ) . "' AND allow_signups = 1 LIMIT 1" ); | ||
} | ||
|
||
// filter the level (for upgrades, etc) | ||
$pmpro_level = apply_filters( 'pmpro_checkout_level', $pmpro_level ); | ||
|
||
// Cache it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix cache code here too.
All Submissions:
Changes proposed in this Pull Request:
Prefixing the
level
,discount_code
, andother_discount_code
parameters at checkout/confirmation. There is still code to support the non-prefixed parameters as a fallback.Other changes include:
pmpro_getLevelAtCheckout()
functionpmpro_default_discount_code
for cases where you want to dynamically add a discount code at checkout (ex Sitewide Sales)pmpro_getLevelAtCheckout()
if a code was usedWith these changes, we should no longer have to reply on the
$pmpro_level
or$discount_code
globals either. We should instead always call thepmpro_getLevelAtCheckout()
function whenever that information is needed, which should be fairly quick now that it is cached.Other information:
Changelog entry