Add login link at the checkout page when not logged in

One of my client want to disable woocommerce account creating form and place a custom link in checkout page if a user not logged in.

At that moment you’ll get the message “You must be logged in to checkout”.

To improve that customers experience doesn’t have to search where to click next, I added extra text with a hyperlink to the “my account/registration” page.

Find this code here
wp-content/plugins/woocommerce/templates/checkout/form-checkout.php

// 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;
}

Replace the code with the 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;
}

Note: You should keep a backup before do the above process. and i recommend you should do this to your child them. Follow the steps to do this

FAQ: How to add a extra link for logged out user in checkout form?

Answer: Follow the steps to add a extra link:

astra-child/woocommerce/checkout/form-checkout.php

Add login link at the checkout page when not logged in

wp-content/plugins/woocommerce/templates/checkout/form-checkout.php

// 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(
%s‘,
$the_url,
esc_html__( ‘My account’, ‘woocommerce’ )
)
);
return;
}

Thanks for reading the post. if you having any issue shout in comment.

Summary
Add login link at the checkout page when not logged in
Article Name
Add login link at the checkout page when not logged in
Description
To improve that customers' experience doesn’t have to search where to click next, I added extra text with a hyperlink to the “my account/registration” page.
Author

1 thought on “Add login link at the checkout page when not logged in”

  1. Rather than redirect buttons it would be good to have the register & login forms here which then after filled in direct back to checkout.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
0 Shares
Tweet
Share
Pin
Share