个性化阅读
专注于IT技术分析

登录重定向后的woocommerce

在我的woocommerce登录表单成功登录中, 它是重定向到我所做的商店页面,

登录错误后应该是同一页面, 但它进入/wp-login.php。我得到了一些代码, 但是当我输入错误的用户名或密码时却可以正常工作, 但是当我输入空的用户名或密码时, 它将进入/ wp-login .php。

这是代码

function my_front_end_login_fail( $username, $password ){
    $referrer = $_SERVER['HTTP_REFERER'];
    if ( !empty($referrer) && !strstr($referrer, 'wp-login') && !strstr($referrer, 'wp-admin') ){
      wp_redirect( $referrer . '?login_failed=failed' );
      exit;
    }
}

你能帮助我吗。


#1


你好, 如果你想在登录后重定向, 你需要做

<?php
/**
* Redirect users to custom URL based on their role after login
*
* @param string $redirect
* @param object $user
* @return string
*/
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
$role = $user->roles[0];
$dashboard = admin_url();
$myaccount = get_permalink( wc_get_page_id( 'shop' ) );
if( $role == 'administrator' ) {
//Redirect administrators to the dashboard
$redirect = $dashboard;
} elseif ( $role == 'shop-manager' ) {
//Redirect shop managers to the dashboard
$redirect = $dashboard;
} elseif ( $role == 'editor' ) {
//Redirect editors to the dashboard
$redirect = $dashboard;
} elseif ( $role == 'author' ) {
//Redirect authors to the dashboard
$redirect = $dashboard;
} elseif ( $role == 'customer' || $role == 'subscriber' ) {
//Redirect customers and subscribers to the "My Account" page
$redirect = $myaccount;
} else {
//Redirect any other role to the previous visited page or, if not available, to the home
$redirect = wp_get_referer() ? wp_get_referer() : home_url();
}
return $redirect;
}
add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 ); 
赞(0)
未经允许不得转载:srcmini » 登录重定向后的woocommerce

评论 抢沙发

评论前必须登录!