In woocommerce, when you enter your personal account instead of the console to open the edit page of the account?

Good time of day. When you open the page My account WooCommerce open Console (dashboard.php). Is it possible instead to make the page that opens edit account edit-account ?
July 2nd 19 at 18:25
2 answers
July 2nd 19 at 18:27
Solution
By default, when you open the My Account page in WooCommerce if the user is not authorized, they are prompted to Login / Register. After entering the url remains the same, the same My Account page, but with a personal data Dashboard (but not the admin Dashboard of WordPress). Url default /my-account/ instead dashboard.php.

As for the redirect to /my-account/edit-account/, then it is done like this:
woo_login_redirect function( $redirect_to ) {

 $redirect_to = wc_customer_edit_account_url();
 return $redirect_to;

}
add_filter( 'woocommerce_login_redirect', 'woo_login_redirect' );

PS: People, don't exaggerate. Always, first and foremost, check the possibility of the engine (in this case - in the order of WooCommerce then WordPress itself) and not the city of crutches. It is quite logical to assume that WooCommerce, which hooks stuck to the eyeballs, has a hook to redirect after login, a simple search of the documentation you'll be given. The same is true of the standard endpoint of vecommerce - it is reasonable to assume that Woo is a helper for obtaining the standard url, for example wc_customer_edit_account_url(). With this approach, you get a reliable solution which will not cease to work if the client is in the admin slug edit the endpoint personal account, or some plugin submenu.

UPDATE 2018: the Code can be slightly shortened and simplified, since we always redirect compulsory and additional checks are expected:
/**
 * Always redirect user to "Edit Account" page after login.
 * 
 * @return string Target URL
*/
woo_login_redirect function()
{
 return wc_customer_edit_account_url();
}
add_filter( 'woocommerce_login_redirect', 'woo_login_redirect' );


If you do not want to put that in a public topic or provide others a possibility to disable this filter can be written as a closure:

/**
 * Always redirect user to "Edit Account" page after login.
 * 
 * @return string Target URL
*/
add_filter( 'woocommerce_login_redirect', function() {
 return wc_customer_edit_account_url();
} );
thank you) helped - hermina.Runte commented on July 2nd 19 at 18:30
: you're welcome :) - Velva.Rogahn commented on July 2nd 19 at 18:33
: Always amazed at people who really really like to complicate my life, and then favor that tupit brakes fell off - Jairo_Durgan commented on July 2nd 19 at 18:36
Igor, and what to do after login is that the user returned to the page from where you came? - lex commented on July 2nd 19 at 18:39
: Put $redirect_to value http_referrer - Velva.Rogahn commented on July 2nd 19 at 18:42
: function woo_login_redirect( $redirect_to ) {

$redirect_to = wc_customer_edit_account_url();
return $redirect_to; http_referrer

}
add_filter( 'woocommerce_login_redirect', 'woo_login_redirect' );

So? - lex commented on July 2nd 19 at 18:45
: Are you kidding me??
woo_login_redirect function( $redirect_to ) {

 if ( wp_get_referer() ) {
 $redirect_to = wp_get_referer();
}
 return $redirect_to;

}
add_filter( 'woocommerce_login_redirect', 'woo_login_redirect' );
- Velva.Rogahn commented on July 2nd 19 at 18:48
: sorry, I'm just learning( - lex commented on July 2nd 19 at 18:51
Thanks, I'll check! - lex commented on July 2nd 19 at 18:54
:
> sorry, I'm just learning(
Well, the basic syntax of PHP and a General understanding of what "assign the value" you have? Because it is not a fact, according to this here:
> return $redirect_to; http_referrer
The wrong way learn. No offense. - Velva.Rogahn commented on July 2nd 19 at 18:57
: well, php is just beginning to explore. no hard feelings! - lex commented on July 2nd 19 at 19:00
: didn't work. The user gets to the console account. - lex commented on July 2nd 19 at 19:03
Probably under the "page from which came" you imeete in mind that which has made the transition to "Account" and received an offer to enter a username and password. But after sabmita of the form of authorization, HTTP_REFERER will contain already the page itself with the form of authorization, which, in turn, is the account page. Try to replace function wp_get_referer() and wp_get_original_referer() - Velva.Rogahn commented on July 2nd 19 at 19:06
: by clicking on the link to enter (prntscr.com/e5ogbr) it opens a popup window, which is requested to login or register. I wish that the user who entered through that window the entrance, returning to the page from which he called the login window. - lex commented on July 2nd 19 at 19:09
I tried to replace

woo_login_redirect function( $redirect_to ) {

if ( wp_get_original_referer() ) {
$redirect_to = wp_get_original_referer();
}
return $redirect_to;

}
add_filter( 'woocommerce_login_redirect', 'woo_login_redirect' );

it did not help. still the user gets to the console - lex commented on July 2nd 19 at 19:12
: Hm, so do you have there a different registration / authentication, what's WooCommerce? Of course you will not have to work. Ask a private question, you have a completely different situation. - Velva.Rogahn commented on July 2nd 19 at 19:15
: Woocommerce — after login, the user returned to the page from which they came? - a solution was found, but why the links to login /registration - duplicated. - lex commented on July 2nd 19 at 19:18
and I was not able to resolve this issue. - lex commented on July 2nd 19 at 19:21
: So Panda you all correctly told. My current solution in this topic does exactly the same thing that he proposed initially. But he then modified the solution to fit your requirements.

The link that supposedly superfluous, it's just that in the code proposed by the Panda:
<a href="<?php echo get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ); ?>/?<?php echo $red_url; ?>" title="<?php _e( 'Login / Register', 'woothemes' ); ?>"><?php _e( 'Login / Register', 'woothemes' ); ?></a>

Here's the link. The text in it replace and all. And the link that you have in Russian, get. - Velva.Rogahn commented on July 2nd 19 at 19:24
AA now I understand. I the link was removed.
now I will try. - lex commented on July 2nd 19 at 19:27
July 2nd 19 at 18:29
For example:
new_dashboard_home function($username, $user){
 if(array_key_exists('administrator', $user->caps)){
 wp_redirect(admin_url('admin.php, 'http'), 301);
exit;
}
}
add_action('wp_login', 'new_dashboard_home', 10, 2);

or this:
function loginRedirect( $redirect_to, $request, $user ){
 if( is_array( $user->roles ) ) { 
 return "/wp-admin/edit.php?post_type=page";
}
}
add_filter("login_redirect", "loginRedirect", 10, 3);
see my answer - hermina.Runte commented on July 2nd 19 at 18:32

Find more questions by tags WooCommerceWordPress