Embed Snippet on Your Site
MemberPress: Redirect Users to a Specific Page Depending on a Custom Field Value
This code snippet adds a custom redirection after registration based on the value of a custom field on the registration form. Here, the custom redirection is triggered if a users chooses a specified value for the specific custom field on registration.
The code snippet requires the use of a custom field on the registration page. The custom field should be created at Dashboard > MemberPress > Settings > Fields tab. In addition, the custom field must contain at least one value which is specified in the code as the trigger for the custom redirection.
The sample code is using the “Company Size” custom field. If a user chooses the specified 500+ option, that user will be redirected to a custom https://mydomain.com/ URL after submitting the registration form.
Note: This code snippet works only if registration is done on the MemberPress registration page through Stripe Elements, Authorize.net, or Offline gateways.
The code should be modified by replacing the mepr_company_size custom field's slug with the slug of the actual field that should be used. In addition, the required value should be specified by replacing the 500+ value with the actual custom field value that should trigger the custom redirection. These modifications should be done on the following lines:
if( isset($_POST['mepr_company_size']) && $_POST['mepr_company_size'] === '500+' ) {
In addition, the dummy https://mydomain.com/ custom redirection URL should be replaced with the actual URL users should be redirected to. The URL can be updated on this line:
return 'https://mydomain.com/';
| |
| |
| |
| |
| |
| |
| |
| |
| |
Comments