Created
April 1, 2025 11:50
-
-
Save xlplugins/07cbbc066f58e87d8546721aee748763 to your computer and use it in GitHub Desktop.
Redirect to my-account page is not logged in user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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