I am using woocommerce and I have created a login and register page. I am not using any plugin for this.
My issue is, I have to check and redirect to log in before checkout I refer to this code(WooCommerce check and redirect to login before checkout)
I am using the below code
add_action('template_redirect', 'check_if_logged_in');
function check_if_logged_in() {
$pageid = 10; // your checkout page id
if (!is_user_logged_in() && is_page($pageid)) {
$url = add_query_arg(
'redirect_to',
get_permalink($pagid),
site_url('/my-account/') // your my acount url
);
wp_redirect($url);
exit;
}
}
but when I click Proceed to checkout then I am getting the URL like
http://examle.com/my-account/?redirect_to=http://example.com/index.php/checkout/