Support » Plugin: WooCommerce » Add login link at the checkout page when not logged in

  • Resolved jordyvanovereem

    (@jordyvanovereem)


    Hello,

    I use the option that people need to have an account to checkout. So the checkout page is blocked. At that moment you’ll get the message “You must be logged in to checkout”.

    To improve that customers don’t have to search where to click next, i want to add extra text with an hyperlink to the “my account/registration” page. How can i do this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • crslz

    (@crslz)

    Hey

    I had to search a bit to get this message because during the checkout you can also offer the option to log into the account (see image).

    https://pasteboard.co/ISu6RWE.jpg

    I don’t know if you were already familiar with these settings?

    However, to answer your question

    You will find this in the following template file

    https://github.com/woocommerce/woocommerce/blob/3.8.0/templates/checkout/form-checkout.php#L26

    There are different ways for this, 1 of which is by overwriting the template file

    * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-checkout.php.

    And add the desired adjustments there

    more information about overwriting template files can be found here

    —————————————————

    Another way is through a filter

    function filter_woocommerce_checkout_must_be_logged_in_message( $message ) {
        $message = 'MY MESSAGE';
        return $message; 
    }
    add_filter( 'woocommerce_checkout_must_be_logged_in_message', 'filter_woocommerce_checkout_must_be_logged_in_message', 10, 1 );

    Regards

    jordyvanovereem

    (@jordyvanovereem)

    Yes i understand, but still wordpress does not give a link to login page in that line. I understand to create the template in the theme folder. But what i cannot get to work is to add another line with a hyperlink to the my account page.

    crslz

    (@crslz)

    Replace this

    // If checkout registration is disabled and not logged in, the user cannot checkout.
    if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
    	echo esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) ) );
    	return;
    }

    With this

    // If checkout registration is disabled and not logged in, the user cannot checkout.
    if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
    	
    	$the_url = '/my-account';
    	
    	echo esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) ) );
    	printf(
    		esc_html__( 'Some text %1$s extra text, extra text', 'woocommerce' ),
    		sprintf(
    			'<a href="%s">%s</a>',
    			$the_url,
    			esc_html__( 'My account', 'woocommerce' )
    		)
    	);
    	return;
    }

    Regards

    Plugin Support Three Sons

    (@3sonsdevelopment)

    Hello @jordyvanovereem,

    It’s been a while since @crslz posted those instructions for you. I’m going to mark this thread as resolved. If you run into trouble, please open up a new topic.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add login link at the checkout page when not logged in’ is closed to new replies.