php 在登录时将WooCommerce客户重定向到商店页面

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 在登录时将WooCommerce客户重定向到商店页面相关的知识,希望对你有一定的参考价值。

<?php
// Ref - https://nicola.blog/2016/03/30/redirect-after-logging-in-based-on-the-user-role/
// add me to functions.php

add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 );
/**
 * 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( 'myaccount' ) );
        $shop = get_permalink( wc_get_page_id( 'shop' ) );

        $wp_role = array( 'administrator','shop-manager','editor','author' ); // add roles that go dashboard

        if ( in_array($role , $wp_role , TRUE)) {
                //Redirect to the dashboard
		$redirect = $dashboard;
        }

	else {
                // Redirect to the shop page
		$redirect = $shop;  // Everyone else goes to Shop page
	}

	return $redirect;
}

以上是关于php 在登录时将WooCommerce客户重定向到商店页面的主要内容,如果未能解决你的问题,请参考以下文章

php 这将在登录WooCommerce时将客户的引用URL重定向。

未登录用户 Woocommerce,重定向

登录重定向后的woocommerce

停止 WooCommerce 将 wp-login.php 和 wp-admin 重定向到帐户页面

Wordpress登录页面重定向到普通用户的Woocommerce我的帐户页面

Woocommerce 客户在 Paypal 重定向之前退出