简体   繁体   中英

Custom Login to WooCommerce Wordpress

I have a custom login form on header

<form method="post" action="http://pwhs.ph.local/wp-login.php">
    <input type="text" placeholder="username" name="username" id="username" />
    <input type="password" name="password" placeholder="password" id="password" />
    '.wp_nonce_field( 'login-nonce' ).'
    <input type="submit" class="btn" name="login" value="Login" />
    <input type="submit" class="btn" name="register" value="Register" />
    <a id="lost-password" href="'.esc_url( home_url( '/my-account/lost-password/' ) ).'">Lost your password?</a>
</form>

It login the user but it directs to WP Dashboard, it should login the user to WooCommerce. I can direct the data to the form-login.php of WooCommerce but how can I login it instead of showing the login form of WooCommerce?

Instead of custom form code, I will suggest you to use plugin eg Theme My Login, Use its shortcode in your them header file so it will display login page and in admin settings set the redirection after login. Please refer following links:

Theme My Login

TML Shortcodes

**add_action( 'init', 'redirect_users_init' );
function redirect_users_init() {
if ( is_admin() && ! current_user_can( 'administrator' ) &&
! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}**

here instead of home_url() you can put the url you need

or you can use this plugin also https://wordpress.org/plugins/wp-hide-dashboard/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM