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

Prefix level and discount code parameters at checkout #2506

Merged
merged 11 commits into from
Aug 10, 2023

Conversation

dparker1005
Copy link
Member

All Submissions:

Changes proposed in this Pull Request:

Prefixing the level, discount_code, and other_discount_code parameters at checkout/confirmation. There is still code to support the non-prefixed parameters as a fallback.

Other changes include:

  • Adding caching to the pmpro_getLevelAtCheckout() function
  • Adding a new filter pmpro_default_discount_code for cases where you want to dynamically add a discount code at checkout (ex Sitewide Sales)
  • Including the discount code used in the level object returned from pmpro_getLevelAtCheckout() if a code was used

With these changes, we should no longer have to reply on the $pmpro_level or $discount_code globals either. We should instead always call the pmpro_getLevelAtCheckout() function whenever that information is needed, which should be fairly quick now that it is cached.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you successfully run tests with your changes locally?

Changelog entry

Enter a summary of all changes on this Pull Request. This will appear in the changelog if accepted.

@dparker1005 dparker1005 changed the title Prefix level param Prefix level and discount code parameters at checkout Jun 7, 2023
@dparker1005 dparker1005 added this to the 3.0 milestone Jul 10, 2023
Copy link
Member

@ideadude ideadude left a 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.

@@ -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();
Copy link
Member

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.
Copy link
Member

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.

@dparker1005 dparker1005 merged commit ea5058b into strangerstudios:v3.0 Aug 10, 2023
@dparker1005 dparker1005 deleted the prefix-level-param branch August 10, 2023 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants