• I’m using a code added in functions.php that require discount code be used to checkout for certain membership level using check payment gateway. The code is working fine by forcing users to enter and apply a valid discount before redirecting to confirmation page.

    But the bad side is when any code is entered in the “discount code space” without clicking on apply when the user click on “Submit and Checkout” the user is redirect to the confirmation page and assigned a membership level.

    How do i solve this to force a valid discount code to entered before redirecting to confirmation page without bypass entering and applying of a valid discount code

    • This topic was modified 8 years, 4 months ago by maundinc.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Andrew Lima

    (@andrewza)

    Hi there,

    Thank you for getting in touch.

    You are able to follow Paid Memberships Pro blog here – https://www.paidmembershipspro.com/require-a-discount-code-to-checkout-for-a-certain-level/

    This touches on exactly what you are wanting to achieve, you mentioned you are using code in your functions.php, are you using the code from this blog?

    Thread Starter maundinc

    (@maundinc)

    The link you paste request i upgrade my membership further before seeing the code. Below is the code i’m using

    ******************************************************************************************

    function my_pmpro_registration_checks_require_code_to_register($pmpro_continue_registration)
    {

    //only bother if things are okay so far
    if(!$pmpro_continue_registration)
    return $pmpro_continue_registration;

    //level = 1, 3 and there is no discount code, then show an error message
    global $pmpro_level, $discount_code;
    //if($pmpro_level->id == 1, 3 && (empty($discount_code) || $discount_code != “REQUIRED_CODE”)) //use this conditional to check for a specific code.
    if($pmpro_level->id == 1 && empty($discount_code) || $pmpro_level->id == 2 && empty($discount_code))

    {
    pmpro_setMessage(“You must use a valid Discount Code to register on this site.”, “pmpro_error”);
    return false;
    }
    return $pmpro_continue_registration;
    }
    add_filter(“pmpro_registration_checks”, “my_pmpro_registration_checks_require_code_to_register”);

    function theme_ob_get_clean() {
    global $theme_ob_stack;
    ob_end_flush();
    return array_pop($theme_ob_stack);

    }

    *************************************************************************************

    I’m able to bypass discount code restriction, by just entering any figures in the Discount Code field, don’t click on apply and click on “Submit and Checkout” twice it will redirect the user to confirmation and assign a membership level.

    ***
    I think there should be an addition code that will verify the code entered in the Discount code field even if not apply.

    • This reply was modified 8 years, 4 months ago by maundinc.
    Plugin Author Andrew Lima

    (@andrewza)

    Here is a link to the gist for the code, it appears to be the same – https://gist.github.com/strangerstudios/5573829#file-gistfile1-txt

    I will have a look at the code and try debug this for you – could you tell me what version of Paid Memberships Pro you are currently using?

    Plugin Author Andrew Lima

    (@andrewza)

    Also regarding your code, could you please adjust it to work on only level 1 for now and not level 1 and 3.

    Please test that and let me know.

    Thread Starter maundinc

    (@maundinc)

    Andrew thank you in advance, after adjusting to work with only level 1, am still able to bypass to confirmation page.

    I am using Paid Memberships Pro Version 1.8.11.2

    Plugin Author Andrew Lima

    (@andrewza)

    Hi @maundinc,

    Thank you for the feedback.

    I am going to try and recreate this issue on my local environment and come up with a solution for you.

    Thank you for your patience.

    Plugin Author Andrew Lima

    (@andrewza)

    I believe the gist file has been updated to do additional checks -> https://gist.github.com/strangerstudios/5573829#file-gistfile1-txt

    You may see the comment on line 14 of the gist – hope this helps.

    Thread Starter maundinc

    (@maundinc)

    I just tried with the gist file https://gist.github.com/strangerstudios/5573829#file-gistfile1-txt

    But the issue is not solved, waiting for the result from your test

    regards

    Thread Starter maundinc

    (@maundinc)

    Hello Andrew hope you doing good, any updates on the above issue?

    Hi,

    I have the same problem few months. Is there already a solution please?
    I have installed all updates (WP, PMPro, …).

    Thank you very much for help.
    Peter

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘discount code restriction bypass’ is closed to new replies.