Display a login modal when trying to access the checkout
Currently I have this redirect in place –
https://stackoverflow.com/questions/48477504/woocommerce-check-and-redirect-to-login-before-checkout
I would like to change it so that when the customer trys to access the checkout (whilst not logged in) a login modal is displayed, rather than redirecting the user anywhere. Then once the user has logged in or registered, they are able to proceed to the checkout.
I am using the “Login/Signup Popup ( Inline Form + Woocommerce )” plugin for the modal.
I’ve tried to alter the snippet to display the modal instead but my PHP is very limited. Please can someone assist?
add_action('display_login_modal','check_if_logged_in');
function check_if_logged_in()
{
$pageid = 257; // Checkout page ID
if(!is_user_logged_in() && is_page($pageid))
{
$shortcode = add_query_arg(
'display_modal',
get_permalink($pageid),
short_code('xoo-el-login-tgr') //Popup shortcode
);
wp_display_modal($shortcode);
exit;
}
}
Leave an answer