Blog

How To Update The Login Link To Go To The WooCommerce Account Page

When building a WooCommerce site, it’s a good idea to use a custom login page instead of the default wp-login.php. Your users will feel far safer and more comfortable when logging into your WooCommerce store if the login page looks like the rest of the site. The default login page doesn’t include any navigation, headers or footers, and unless you’re using a plugin will have the WordPress logo instead of your own. This is far from a coherent user experience, and could lead to the loss of a potential customer.

Updating Your Store’s Login URL

The code below will automatically redirect any logged out visits to /wp-admin instead to the WooCommerce login page, as well as updates any other functions that are displaying a link to the login page. This will provide a more consistent user experience to your store’s customers.

You can add this code to your theme’s functions.php file, or to a custom functional plugin.

<?php
add_filter( 'login_url', 'cameronjonesweb_use_woocommerce_login_page' );
/**
* If WooCommerce is active use the account page for logging in
* @param string $login_url The URL for login.
* @param string $redirect The URL to redirect back to upon successful login.
* @param bool $force_reauth
* @return string
*/
function cameronjonesweb_use_woocommerce_login_page( $login_url ) {
if( function_exists( 'is_woocommerce' ) && $wc_account_page = get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ) {
$login_url = $wc_account_page;
}
return $login_url;
}

Bonus tip: Make sure you are using an SSL certificate on any eCommerce site to help protect your users details.

Did you find this post useful?

YesNo