Last active
October 9, 2019 13:18
-
-
Save finalwebsites/71a39f7eb34d031fa5d4f6c422d0fa44 to your computer and use it in GitHub Desktop.
Redirect to the WooCommerce checkout page after login
This file contains 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
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.