A
A
AltaiR2016-11-08 17:43:17
WordPress
AltaiR, 2016-11-08 17:43:17

How to open the account editing page instead of the console in woocommerce when entering your personal account?

Good day. When opening the My Account WooCommerce page, the Console ( dashboard.php ) is opened. Is it possible to make it open the edit-account page instead ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Vorotnev, 2016-11-09
@AltaiR-05

By default, when opening the My Account page in WooCommerce, if the user is not authorized, he is prompted to Login / Register. After logging in, the same url remains, the same My Account page, but with personal data - Dashboard (but not the Dashboard of the WordPress admin). The default url is /my-account/, not dashboard.php.
As for redirecting to /my-account/edit-account/, it is done like this:

function woo_login_redirect( $redirect_to ) {

     $redirect_to = wc_customer_edit_account_url();
     return $redirect_to;

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

PS: People, do not complicate. Always, first of all, check the capabilities of the engine (in this case, WooCommerce is ok, then WordPress itself) and do not make crutches. After all, it is quite logical to assume that WooCommerce, which is stuffed with hooks to the eyeballs, has its own hook for a redirect after login, a simple search in the documentation will give it to you. The same goes for getting the standard woocommerce endpoint - it's reasonable to assume that Woo has helpers for getting standard urls, like wc_customer_edit_account_url() . With this approach, you get a reliable solution that will not stop working if the client edits the endpoint slug of the personal account in the admin panel, or some plugin replaces it.
UPDATE 2018: The code can be shortened and simplified a little, since we always have a forced redirect and no additional checks are expected:
/**
 * Always redirect user to "Edit Account" page after login.
 * 
 * @return string Target URL
 */
function woo_login_redirect()
{
  return wc_customer_edit_account_url();
}
add_filter( 'woocommerce_login_redirect', 'woo_login_redirect' );

If it is not intended to be inserted into a public topic or to allow others to turn off this filter, it 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();
} );

I
Ivan Kozlov, 2016-11-09
@trampick

For example like this:

function new_dashboard_home($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 like 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);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question