1. Home
  2. Knowledge Base
  3. WooCommerce Members Only
  4. Filtering the redirect URL
  1. Home
  2. Knowledge Base
  3. Advanced
  4. Filtering the redirect URL

Filtering the redirect URL

If you want to change the page that users are redirected to, you can add this small script to your functions.php file or snippets file:

<?php
/**
* Change the URL that users are redirected to
*/
function prefix_redirect_url( $url ) {
return 'http://yournewurl.com/';
}
add_filter( 'wcmo_redirect_url', 'prefix_redirect_url' );

Don’t forget to update the URL…

Filter redirect based on user role

You can filter the redirect URL based on the current user’s role – so you can direct Gold Members to a different page from Silver Members for example:

<?php
/**
* Change the redirect URL depending on user role
*/
function prefix_redirect_url_per_role( $url ) {
// Get the current user roles
$roles = wcmo_get_current_user_roles();
if( in_array( 'gold', $roles ) ) {
// Redirect to specific page for Gold role
return 'http://yournewurl.com/gold';
} else if( in_array( 'silver', $roles ) ) {
// Redirect to specific page for Gold role
return 'http://yournewurl.com/silver';
}
// This is the default URL
return $url;
}
add_filter( 'wcmo_redirect_url', 'prefix_redirect_url_per_role' );

You’ll need to edit the snippet to include your user roles.

Was this article helpful?

Need More Support?

If you can't find the answer that you're looking for, then please use the link below to raise a support ticket.
Contact Support

Related Articles