Redirect Woocommerce Checkout Payment Page before login to Auth0
Known:
Payment Email had this link :
https://staging.a2fahmi.com/checkout/order-pay/286816/?pay_for_order=true&key=wc_order_PgmKQfGnVVzTu
Wanted:
I want when customer have buy some stuff then checkout and logout then he clicked payment email then he redirect to Auth0 login
Problem:
When customer clicked the payment email then he still redirected to Woocommerce login form
Question:
How to redirect the woocommerce checkout payment page login to Auth0 login … ?
Answer:
Add this code inside your themes function.php:
if(!is_user_logged_in()){
if ( isset($_GET['pay_for_order'] ) ) {
$current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
wp_redirect( wp_login_url( $current_url) );
exit;
}
}