How to create a WooCommerce customer login shortcode, page and widget

This article will show you how to create a WooCommerce customer login shortcode. We will also explore all aspects of WooCommerce customer login in this comprehensive guide, covering various methods for users to access your online store and the underlying reasons behind each approach.

The WooCommerce customer login form is an integral part of WordPress user management, serving as a secure gateway for customers to access their accounts on WooCommerce-powered websites, facilitating personalized experiences, order tracking, and seamless online transactions.

Easy login forms are great for improving your site’s usability. If you have many login options, ensure your users won’t be lost on your site. This allows them to quickly place new orders, as well as track old ones.

woocommerce customer login

WooCommerce’s original solution uses a login form in the user profile and other pages. But this still doesn’t have the flexibility aspect that we need. That’s why, in this article, we will explore the different WooCommerce login options and customize the WooCommerce login method by creating our custom login form shortcode.

Thus, this shortcode can be used on any of your pages. It can also be used in widget areas or your template files. This will allow you to create your own WooCommerce custom login page without a plugin.

Let’s get started!

Different types of WooCommerce login setups

A WooCommerce store can be structured in a few different ways to meet its customers’ requirements.

1. Public WooCommerce store

A public WooCommerce store is the default and the most common setup. Anyone can browse your products, and there is no hidden WooCommerce content. Customers can buy products as guests without having to log in or optionally sign up and create an account during the guest checkout. Opting for a public WooCommerce store with guest checkout is a prevalent choice among customers, offering fast purchases and minimizing abandoned carts by requiring minimal personal information and no customer login and password. While this approach is favored for its efficiency (allowing customers a quick WooCommerce checkout), the trade-off lies in the limited customer data available for marketing and customer analysis. The debate over allowing or restricting guest checkout is a common topic among store owners, a discussion that will be elaborated upon towards the end of this article.

2. Public WooCommerce store with required user registration

This is similar to the default setup in that all the products in the store are public and can be browsed by anyone. Still, customers must register (by creating a customer account via a dedicated WooCommerce registration page or by automatically creating a customer account on the checkout page) or log to their account page to make a purchase. They can log in via their custom WooCommerce login page or a WooCommerce social login plugin. Opting for a public WooCommerce store with mandatory user accounts offers a strategic eCommerce approach, promoting repeat purchases through integrated login processes for efficient transactions. This setup allows the integration of order history, personalized recommendations, and loyalty promotions. However, the potential drawback lies in customers managing an additional account, surrendering personal information, and the possible purchase barrier associated with account setup during checkout.

3. Private and protected WooCommerce products and product categories

With this setup, customers can view your products and make purchases on your WooCommerce site, but only customer accounts created to view specific products have access to certain things. For example, all customers can purchase from any public area of your website that doesn’t contain hidden content. Only customer accounts with specific roles and privileges can view and purchase certain products or receive special customer service. Creating a private WooCommerce store with mandatory login, whether through exclusive memberships or closed sections for members, emphasizes exclusivity and specialized access. Similarly, a customer portal with protected product categories allows segmented shopping experiences, but both models require users to set up accounts and work best in specific niches.

4. WooCommerce Customer Portal:

A WooCommerce client portal is a private, secure WooCommerce customer area on your website where you can share and exchange confidential information. It provides tools that help your clients share information with you and each other and communicate efficiently. The WooCommerce customer portal usually has password-protected product categories. It can be valuable as a self-service tool in a private customer area. This allows specific users or user roles to access certain areas of the WooCommerce store. Customers can view and purchase products from the public areas of the shop, while only those with the correct credentials can access the protected categories. Creating private WooCommerce stores, whether through exclusive memberships or complete store privacy requiring login or a password, is a popular approach for exclusivity. Success depends on a top-tier product or service portfolio.

5. Social Logins for WooCommerce Store

Integrating social logins into your WooCommerce store presents a streamlined approach to customer access. Various plugins authenticate users through their social media accounts, reducing the login hassle and shortening the path to purchase. Additionally, with the WooCommerce login feature, customers can effortlessly log in during the checkout process, providing flexibility in registration options and catering to the 77% of users who prefer social media logins for their convenience and security, especially when utilizing the official WooCommerce extension.

Default WooCommerce customer login options

WooCommerce has some out-of-the-box options for user login. Usually, the login form is presented whenever you visit a WooCommerce page for registered users.

The first instance is the “My Account” page, usually under /my-account. You can see the login and registration forms on this page.

Depending on your setup, the checkout page may also contain the login form. The main difference here is the inline opening form. Therefore, once you click “log in”, the form opens up as an accordion. That’s a great solution to save space and keep users on the checkout workflow.

If you want the login form by itself, though, WooCommerce has no option. Now, let’s build our shortcode to change this.

By default anyone can browse your products and there is no hidden WooCommerce content.

How to customize the user login in WooCommerce

There are a few different ways that you can use to customize your WooCommerce login page. The first and the most obvious is using a dedicated WordPress theme that provides an out-of-the-box custom login page. The other alternative is to customize your login page using a dedicated user registration WordPress plugin. To create a customer login page, you must install and configure a WordPress plugin like the User Registration plugin. If they haven’t logged in before, you can then use this plugin to create a customer login or registration form. Since both of these ways are pretty straightforward in this tutorial, we will focus on creating a custom WooCommerce login form and shortcode programmatically with some custom code.

Unlock the Full Potential of Your WooCommerce Customer Data

How to create a WooCommerce login shortcode

The first step in our shortcode is to register the shortcode in the WordPress add_shortcode() function. This is its primary structure, along with the main points in our code:

The name is what you use in your square brackets – in this case, the code registers a shortcode that can be used as [my_wc_login_form]. And the function name is what WordPress calls to render the shortcode content.

By this point, the code will not do anything. Now let’s start implementing the above-listed steps one by one.

1. Check if the user is logged in

We want to check if users are logged in, and if they are – we’ll display a welcome message. If users aren’t logged in, then we do our magic to display the form.

You can also check if a user is logged in with Users Insights. You will need to just apply the last seen filter and set the days field to less than one:

woocommerce login user

The green dot on the left side from the user profile picture is indicated in that the WooCommerce user is currently online.

2. Display login form

For the non-logged-in users, we can display our login form. But we need to know if the WooCommerce functions that render the form are available. We can do this by using the function_exists() function.

This code renders the login form:

  • the woocommerce_login_form() the function prints the form markup. The woocommerce_output_all_notices() function will print any login errors, such as invalid username/password errors.
  • we use ob_start() and ob_get_clean() since the WooCommerce functions echo the markup, and the shortcode is supposed to return the markup instead of printing it.
  • if the WooCommerce login functions are not present, we render the default WordPress login with the wp_login_form() function

Important: please keep in mind that the WooCommerce functions that we used here might change in the future. Therefore it is always highly recommended to always test your code after updating your WooCommerce plugin.

And this is the final version of our code:

At this point, you might ask yourself – why use the WooCommerce login form functions instead of directly using the WordPress login form function? There are a few advantages of using the WooCommerce form, such as:

  • Consistent input element style – since the form uses the default WooCommerce classes for its elements, it will look the same way as the other WooCommerce login forms on your site
  • Better error handling – if the authentication fails, the WooCommerce form will display a message on the same page, while the WordPress form will redirect your users to the default WordPress login page

Now, let’s use the login shortcode on your site.

How to use the WooCommerce login shortcode

You can apply this shortcode in almost any place you want. But let’s add it to one of our pages. For example, if you have a login page, you can create it this way:
Add WooCommerce login shortcode

And this is the result:
WooCommerce login form

On the other hand, you can use this shortcode in your sidebars. This is my favorite, as it fits nicely in the sidebar area. This is how you create it in your widget areas:
Add WooCommerce login shortcode to sidebar

And this is the result we have:
WooCommerce login shortcode in sidebar

Furthermore, you can use your WooCommerce login shortcode in your template files or inside of other shortcodes. For other shortcodes, this depends on your current plugins. Usually, sliders, columns, accordions, and other elements allow shortcodes in them. For a template edit, you can apply it with this code:


Today, we looked into how to create your WooCommerce login shortcode. You can use his shortcode anywhere you want. This makes it powerful for a solution in a page, widget, slider, or even in other shortcodes.

We hope you enjoyed this article and see you again next time!