1. Home
  2. Knowledge Base
  3. WooCommerce Wholesale Lead Capture
  4. Registration
  5. Custom Redirections For Wholesale Registration Page

Custom Redirections For Wholesale Registration Page

Redirection for Multiple Wholesale Registration Pages

Since we’ve introduced Wholesale Registration shortcodes to create multiple registration forms, there have been some requests on how to redirect other registration forms to a different page.

By default, the Wholesale Registration page redirects to the Wholesale Thank You page found on your WooCommerce > Settings > Wholesale Lead > General. But by using the custom snippet below, you can change the URL of the redirection based on the Page ID of the Wholesale Registration page that you want to get redirected.

add_filter( 'wwlc_create_user_response_data', function( $response ) {
$url     = wp_get_referer();
$page_id = url_to_postid( $url );

if( $page_id === 5213 ) {
if( $response[ 'status' ] == 'success' ) {
$response[ 'redirect' ] = 'https://facebook.com/';
}
}
return $response;
}, 99, 1 );

Redirection based on the value of the custom field

Another useful snippet that you can use is for redirecting the user after a successful registration to a specific page based on the value/option selected in your custom field (radio).

As an example, I have created wwlc_cf_radio in the WooCommerce > Settings > Wholesale Lead > Custom Fields.

function my_wwlc_register_custom_redirect( $response ) {

if( $response[ 'status' ] == 'success' ) {
$custom_field_val = get_user_meta( $response[ 'user_id' ] , 'wwlc_cf_radio' , true );
if( $custom_field_val == 'Yes' )
$response[ 'redirect' ] = 'https://wholesalesuiteplugins.com/';
}

return $response;

}

add_filter( 'wwlc_create_user_response_data', 'my_wwlc_register_custom_redirect', 99, 1 );

The snippet above will redirect the users who selected YES on the custom radio field on the Wholesale Registration page. Simply change the sample link in the snippet to your desired URL.

Redirect a Successful Registration based on the Wholesale Registration Page Language

Another redirection snippet that you can use is based on the language of the Wholesale Registration page.

The snippet below will check if the language is set to English (en_US) and it will redirect it to the URL provided.

If you wish to add more language redirection, simply add another if condition to check if the $lang variable is equal to the language the user is registering. Here’s the link where you can get the language code for the language used in WordPress. Afterward, feel free to change the respective URL for the language you want it to be redirected.

function my_wwlc_register_custom_redirect( $response ) {
$lang = get_locale();

if( $response[ 'status' ] == 'success' ) {
if ($lang=='en_US'){
$response[ 'redirect' ] = 'https://facebook.com/';
}
}
return $response;
}
add_filter( 'wwlc_create_user_response_data', 'my_wwlc_register_custom_redirect', 99, 1 );[/php]

To use the custom snippets provided above, simply put them on your theme/child theme’s functions.php to enable them to work on your site.

Please note that these custom snippets may require some coding background if you wish to further customize them.

Was this article helpful?

Related Articles