Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
WooCommerce how to perform a redirection for not logged in users

I need a redirection for all not logged-in users on my WordPress site.

All of them should every time be redirected to the login site. So that nobody without a login can access the site. Important is, I made this redirection because I have an API that also needs to have access to the site if I would do this with .htaccess the API hadn't have any access to the information.

I used the following PHP code:

add_action('template_redirect','woo_check_loggedin');
function woo_check_loggedin(){

      if(!is_user_logged_in() && !is_page(lost-password) ){
          wp_redirect("https://example.com/wp-login.php");
          exit;
      }
 
   }

But this only works, when I go to "example.com". When I enter directly the URL "example.com/shop" you can still visit the site. How can I avoid this?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You could use the request property of the wp global variable and wp_login_url function.

add_action('template_redirect', 'woo_check_loggedin');

function woo_check_loggedin()
{
    global $wp;

    if (
        !is_user_logged_in() 
        && 
        'my-account/lost-password' != $wp->request
       ) 
      {
        wp_safe_redirect(wp_login_url(get_permalink()));
        exit;
      }
}

This answer has been tested on woo 6.1 and works!

Related answers for redirection on Wooommerce:

  • https://stackoverflow.com/a/70137563/15040627
  • https://stackoverflow.com/a/70395951/15040627
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda