skip to Main Content

I have found this code that after adding an item to cart, if the customer isn’t logged in they are redirected to a login page. At the moment I am getting an error, I think I haven’t edited the code properly.

function wpse_131562_redirect() {
    if (
        ! is_user_logged_in()
        && (is_cart() || is_checkout())
    ) {
        // feel free to customize the following line to suit your needs
        wp_redirect('myshop.co.uk/sign-in'());
        exit;
    }
}
add_action('template_redirect', 'wpse_131562_redirect');

2

Answers


  1. Yes, the function wp_redirect is wrong.

    wp_redirect( 'https://myshop.co.uk/sign-in' ); should do the job

    Login or Signup to reply.
  2. Without https:// it is giving error. you should use home url dynamic try the following code

    wp_redirect(get_home_url().'/sign-in');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search