Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xlplugins/07cbbc066f58e87d8546721aee748763 to your computer and use it in GitHub Desktop.
Save xlplugins/07cbbc066f58e87d8546721aee748763 to your computer and use it in GitHub Desktop.
Redirect to my-account page is not logged in user
add_action('template_redirect', 'redirect_to_account_if_not_logged_in');
function redirect_to_account_if_not_logged_in() {
// Check if the user is trying to access the checkout page and is not logged in
if (is_checkout() && !is_user_logged_in()) {
// Redirect to the My Account page (WooCommerce login/register page)
wp_redirect(wc_get_page_permalink('myaccount'));
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment