Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save greathmaster/b0d29eaa2bdf2f2651b6d4ecbe1f4eac to your computer and use it in GitHub Desktop.
Save greathmaster/b0d29eaa2bdf2f2651b6d4ecbe1f4eac to your computer and use it in GitHub Desktop.
PMPro confirmation URL redirection based on discount code AND membership level
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