woocommerce php snippets for proceeded to checkout

2019-09-08 10:57发布

I am using woocommerce theme shopkeeper and i have problem with proceed to checkout functionality i need a php snippet code for checking the user is login or not when he click a button of proceed to checkout on cart page

3条回答
Animai°情兽
2楼-- · 2019-09-08 11:28

You have to use simple wordpress function to check is a user logged in or not. is_user_logged_in()

Checks if the current visitor is a logged in user. it returns (bool) True if user is logged in, false if not logged in.

  <?php
    if ( is_user_logged_in() ) {
        echo 'Welcome, registered user!';
    } else {
        echo 'Welcome, visitor!';
    }
    ?>
查看更多
Bombasti
3楼-- · 2019-09-08 11:43
add_action('woocommerce_checkout_process', 'check_if_user_loggedin');
function check_if_user_loggedin() {
if ( is_user_logged_in() ) {
    echo 'Logged user';
} else {
    echo 'Guest user!';
}
}
查看更多
啃猪蹄的小仙女
4楼-- · 2019-09-08 11:50

First you need to check user in on checkout page or not, if so then do the checking; or if you have your own function then you can simply wordpress is_user_logged_in() function.

add_action('wp', 'xyz_checkLoggedIn');

function xyz_checkLoggedIn() {
    if (is_checkout()) {
        if (is_user_logged_in()) {
            //user is logged in
        } else {
            //user is not logged in
        }
    }
}

Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.
The code is tested and fully functional.

Hope this helps!

查看更多
登录 后发表回答