Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Last active October 9, 2019 13: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 finalwebsites/71a39f7eb34d031fa5d4f6c422d0fa44 to your computer and use it in GitHub Desktop.
Save finalwebsites/71a39f7eb34d031fa5d4f6c422d0fa44 to your computer and use it in GitHub Desktop.
Redirect to the WooCommerce checkout page after login
<?php
add_filter( 'woocommerce_registration_error_email_exists', function( $html ) {
$url = wc_get_page_permalink( 'myaccount' );
$url = add_query_arg( 'redirect_checkout', 1, $url );
$html = str_replace( 'Please log in', '<a href="'.$url.'"><strong>Please log in</strong></a>', $html );
return $html;
} );
add_filter( 'woocommerce_login_redirect', function( $redirect, $user ) {
if ( $_GET['redirect_checkout'] ) {
return wc_get_checkout_url();
} elseif ( wp_get_referer() ) {
return wp_get_referer();
} else {
return $redirect;
}
}, 10, 2 );
@finalwebsites
Copy link
Author

I don't like to use the regular login form for the checkout page. So I wrote these two filters to add:
a) a link to the regular login page (if the user's email address exists)
b) a redirect to the checkout page after login.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment