Skip to content

Instantly share code, notes, and snippets.

@sunshinephotocart
Last active May 31, 2023 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunshinephotocart/36cab6efcb29ce20efe45e8b7ff0ec4e to your computer and use it in GitHub Desktop.
Save sunshinephotocart/36cab6efcb29ce20efe45e8b7ff0ec4e to your computer and use it in GitHub Desktop.
Redirect to login or registration if not logged in at checkout
// Redirects to Login page.
add_action( 'template_redirect', function() {
global $sunshine;
if ( ! is_user_logged_in() && is_page( $sunshine->options['page_checkout'] ) ) {
wp_redirect( wp_login_url( get_permalink( $sunshine->options['page_checkout'] ) ) );
exit;
}
});
// Redirects to Registration page.
add_action( 'template_redirect', function() {
global $sunshine;
if ( ! is_user_logged_in() && is_page( $sunshine->options['page_checkout'] ) ) {
wp_redirect( wp_registration_url( get_permalink( $sunshine->options['page_checkout'] ) ) );
exit;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment