Registration form for non registered customer after click on checkout
-
I have configured my store to avoid checkout for non registered users (I want to keep the store with that configuration)
Please, could you tell what modifications I have to do to my page in order to automatically redirect to the account creation screen (attach 1) the customer that are not logged in and try to checkout any product?
In this moment, the customer that are not logged in and try to checkout any product is redirected to an screen that shows next text “You must log in to make the payment” (attach 2)
Attachments:
You must be
logged in to view attached files.
// if the user is not logged in, return him to login before checkout
add_action('template_redirect', 'check_if_logged_in');
function check_if_logged_in() {
if ( ! is_user_logged_in() && is_checkout() ) {
$url = site_url('/my_account/');
wp_redirect( $url );
exit;
}
}
// redirect to checkout after login (or registration)
add_filter( 'woocommerce_registration_redirect', 'redirect_after_login_or_registration_to_checkout_page' );
add_filter( 'woocommerce_login_redirect', 'redirect_after_login_or_registration_to_checkout_page' );
function redirect_after_login_or_registration_to_checkout_page() {
// only if the cart is not empty
if ( ! WC()->cart->is_empty() ) {
return wc_get_page_permalink( 'checkout' );
} else {
return home_url();
}
}
Hello,
By default, Woocommerce does not provide such an option. Our support does not cover the investigation and fixing third parties codes.
You would better to try to find a plugin for such services.
If you have any questions please feel free to contact us.
Best Regards
Thank you so much iamfahrig, your code did the work.
Best regards!
Hello,
You would better try to find an appropriate plugin.
If you have any questions please feel free to contact us.
Best Regards