6

我已经搜索了这个问题的答案,使用了插件,但仍然没有任何效果。我希望我网站的用户在登录/注册后被重定向到主页。

目前,用户登录并被重定向到我的帐户页面。

Woocommerce 提供了此代码,但它对我不起作用:

/*
 * goes in theme functions.php or a custom plugin
 *
 * By default login goes to my account
 **/
add_filter('woocommerce_login_widget_redirect', 'custom_login_redirect');

function custom_login_redirect( $redirect_to ) {
     $redirect_to = 'http://anypage.com';
}

我也尝试使用 Peter's Redirect 插件,但由于 woocommerce 绕过 wp-login.php,它不起作用。

想法?

4

8 回答 8

4

您可以下载http://wordpress.org/extend/plugins/peters-login-redirect/并将其替换为 widget-login.php

<input type="hidden" name="redirect_to" class="redirect_to" value="<?php echo $redirect_to; ?>

<input type="hidden" name="redirect_to" class="redirect_to" value="<?php echo site_url('/wp-content/plugins/peters-login-redirect/wplogin_redirect_control.php/'); ?>" />

这样,您可以使用 peters 登录重定向来重定向使用 woocommerce 登录小部件的全局和特定用户。

确保更改“使用外部重定向文件。如果您使用的插件(例如 Gigya)绕过常规 WordPress 重定向过程(并且只允许一个固定的重定向 URL),请将其设置为“是”。然后,将重定向 URL 设置为 % s”设置为“YES”。

希望这可以帮助。

于 2013-03-25T08:40:44.257 回答
4

在functions.php上使用此代码

add_filter('woocommerce_login_redirect', 'wc_login_redirect');
function wc_login_redirect( $redirect_to ) {
     $redirect_to = 'https://www.google.co.in/';
     return $redirect_to;
}
于 2015-07-27T08:11:47.513 回答
2

他们提供的修复仅在您使用登录小部件时才有效。登录到主页后,您需要做的就是将用户重定向到您的登录表单中:

<input type="hidden" name="redirect" value="<?php echo get_home_url(); ?>" />
于 2012-10-17T00:21:43.260 回答
0

做这个:

转到管理 > Woocommerce > 设置 > 常规

在“购物车、结帐和帐户”下找到“客户帐户”

取消选中“阻止客户访问 WordPress 管理员”

保存更改并测试!

于 2014-07-22T18:44:54.093 回答
0

最近添加了一个过滤器,允许您在注册后重定向。登录时进行重定向就像上面提到的 Tomanow 一样简单(将其放在 form-login.php 中)。这是过滤器的链接以及在注册表单上处理此过滤器的一些说明。

https://github.com/woothemes/woocommerce/commit/014e31952828377bf7a1ebf4e812a43d0bcefa67#commitcomment-3351995

于 2013-06-04T18:27:17.030 回答
0

在functions.php上使用此代码

add_action('wp_logout','go_home');
function go_home(){
  wp_redirect( home_url() );
  exit();
}
于 2014-02-17T13:30:01.313 回答
0

您可以根据用户角色设置重定向。下面给出了该重定向的代码,我为入门级用户或技术或非程序员开发了一个WooCommerce 登录或注册重定向插件。

 //Redirect users to custom URL based on their role after login

function wp_woo_custom_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( 'my-account' ) );

if( $role == 'administrator' ) {

    //Redirect administrators to the dashboard
    $admin_redirect = get_option('admin_redirect');
    $redirect = $admin_redirect;
} elseif ( $role == 'shop-manager' ) {

    //Redirect shop managers to the dashboard
    $shop_manager_redirect = get_option('shop_manager_redirect');
    $redirect = $shop_manager_redirect;
} elseif ( $role == 'customer' || $role == 'subscriber' ) {

    //Redirect customers and subscribers to the "My Account" page
    $customer_redirect = get_option('customer_redirect');
    $redirect = $customer_redirect;
} 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', 'wp_woo_custom_redirect', 10, 2 );
于 2016-09-25T07:14:06.810 回答
-1

还包括使用 wp-login.php 的标准 WordPress 登录表单登录:

add_filter('login_redirect', 'custom_login_redirect');

我使用此过滤器和您提供的过滤器,针对相同的过滤器功能,它捕获用户可能登录的两个地方(WP 和 WC)。

也刚刚注意到明显的问题。您的过滤器功能中有这个:

$redirect_to = 'http://anypage.com';

但你需要这个:

return 'http://anypage.com';

$return_url 是从以前的过滤器传入的,因此您可以检查它并决定是否更改它。

编辑:

实际上,我需要纠正其中的一些。看起来 woocommerce_login_widget_redirect 过滤器用于在小部件登录表单中设置重定向参数。这意味着它仅在用户未登录并且显示小部件登录表单时触发。它不能用于决定用户登录后将其发送到哪里。

WP login_redirect 过滤器在用户登录触发,并且可以修改随登录表单发送的任何 redirect_to URL,以使您能够将用户重定向到其他页面。

此外,WooCommerce 登录小部件不会处理您认为的登录。登录过程是通过 woocommerce-ajax.php 中的 AJAX 处理的。您将在其中看到重定向 URL 没有通过 woocommerce_login_widget_redirect 过滤器传递,因此无法修改。我将把它作为一个拉取请求向 WooCommerce 提出,因为我认为它应该被过滤。

https://github.com/woothemes/woocommerce/pull/2508

于 2013-02-18T15:17:53.303 回答