Display a Login Modal when user is not logged in trying to access Checkout
I am newbie to wordpress and my PHP is very limited also.
Currently I have this redirect in place –
https://stackoverflow.com/questions/48477504/woocommerce-check-and-redirect-to-login-before-checkout
However 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.
These are the shortcode options it gives:
As I mentioned, this is my first experience with PHP so I am still learning the basics, here is what I came up with at a completely uneducated guess, using the redirect script as a template –
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;
}
}
I know it’s way off so any help or tips would be greatly appreciated!
Cheers
Leave an answer