1. Home
  2. Knowledge Base
  3. WooCommerce Members Only
  4. Advanced
  5. Redirect to different URL depending on password
  1. Home
  2. Knowledge Base
  3. WooCommerce Members Only
  4. Redirect to different URL depending on password

Redirect to different URL depending on password

If you are using passwords as your restriction method, you can redirect users to different URLs depending on which password they use.

To enable this, you’ll need to add this snippet to your site. See this article if you’d like to know how best to add a snippet to your site.

<?php
/**
* Filter the Members Only redirect URL based on the password entered
* @param $url The default URL to redirect to after entering the correct password
* @param $password The password entered by the user
* @return URL The new URL to redirect to
*/
function prefix_wcmo_redirect_url( $url, $password ) {
if( $password == 'green' ) {
$url = get_category_link( 19 ); // Replace '19' with the ID of your product category
}
return $url;
}
add_filter( 'wcmo_redirect_url', 'prefix_wcmo_redirect_url', 10, 2 );

In the example above, the user will be redirected to the WooCommerce archive page for the category with the ID of 19 – if they correctly enter ‘green’ as the password.

You can set up multiple passwords and redirect the user to a different URL for each using this method.

Was this article helpful?

Related Articles