Forked from greathmaster/pmpro-confirmation-url-redirect-with-discount-code.php
Created
September 24, 2020 21:01
-
-
Save kimwhite/56957ebe83afdbca1ab5b640354cf219 to your computer and use it in GitHub Desktop.
PMPro confirmation URL redirection based on discount code AND membership level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This recipe will allow you to redirect a new signup who has used a Discount Code | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_confirmation_url($rurl, $user_id, $pmpro_level) | |
{ | |
global $wpdb; | |
$code = $wpdb->get_row("SELECT * FROM $wpdb->pmpro_discount_codes WHERE id = $pmpro_level->code_id LIMIT 1"); | |
/* | |
Example of $code content: | |
object(stdClass) { | |
public 'id' => string '7' (length=1) | |
public 'code' => string 'SC916E8F9CC' (length=11) | |
public 'starts' => string '2019-04-08' (length=10) | |
public 'expires' => string '2029-04-08' (length=10) | |
public 'uses' => string '100' (length=3) | |
} | |
*/ | |
if(isset($code)) { | |
if($code->code == 'SC916E8F9CC' && pmpro_hasMembershipLevel(1)) | |
$rurl = "http://example.com/page_1"; | |
if($code->code == 'X84HJ8F9CC' && pmpro_hasMembershipLevel(2)) | |
$rurl = "http://example.com/page_2"; | |
if($code->code == 'JU486E8F9CC' && pmpro_hasMembershipLevel(3)) | |
$rurl = "http://example.com/page_3"; | |
} | |
return $rurl; | |
} | |
add_filter('pmpro_confirmation_url', 'my_pmpro_confirmation_url', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment