Typek – Blog

How to Remove the Login Form in WooCommerce Using PHP Snippet

In this tutorial, we will learn how to remove the login form in WooCommerce using a PHP snippet. Removing the login form can be useful if you want to disable the default WooCommerce login form and use a custom login solution or if you want to restrict access to your WooCommerce store to only specific users. We will cover two different methods to achieve this: using a PHP snippet in your theme’s functions.php file and using a custom plugin. Before we start, make sure you have access to your WordPress site’s files, either through an FTP client or the file manager in your hosting control panel.

1. Understanding the WooCommerce Login Form

The default WooCommerce login form is displayed on the My Account page and allows users to log in to their accounts or register for a new account. By default, this form is included with WooCommerce and is displayed on the frontend of your site. If you want to remove this form, you can do so using a PHP snippet.

2. Removing the Login Form Using a PHP Snippet in Your Theme’s functions.php File

The first method to remove the login form in WooCommerce is by adding a PHP snippet to your theme’s functions.php file. This method is recommended if you are using a child theme and want to keep the changes you make separate from the parent theme. Follow the steps below to remove the login form using this method:

  1. Access your WordPress site’s files using an FTP client or the file manager in your hosting control panel.
  2. Navigate to the folder of your active theme. This is typically located in /wp-content/themes/your-theme/.
  3. Open the functions.php file in a text editor.
  4. Add the following PHP snippet at the end of the file:

// Typek_remove_login_form_in_woocommerce
function typek_remove_login_form_in_woocommerce() {
  if (is_account_page()) {
    remove_action('woocommerce_account_navigation', 'woocommerce_account_navigation');
    remove_action('woocommerce_before_customer_login_form', 'woocommerce_login_form');
    remove_action('woocommerce_before_customer_login_form', 'woocommerce_output_all_notices', 10);
  }
}
add_action('wp', 'typek_remove_login_form_in_woocommerce');

This PHP snippet checks if the current page is the My Account page and then removes the login form and the associated notices by removing the relevant WooCommerce actions. By adding this code to your theme’s functions.php file, you are effectively removing the login form from the My Account page.

  1. Save the changes to the functions.php file and upload it back to your server if necessary.
  2. Visit your WooCommerce My Account page to confirm that the login form has been removed.

If you want to remove the entire My Account page content and not just the login form, you can use the following PHP snippet instead:


// Typek_remove_my_account_page_content
function typek_remove_my_account_page_content() {
  if (is_account_page()) {
    remove_action('woocommerce_account_content', 'woocommerce_output_content_wrapper', 10);
    remove_action('woocommerce_account_content', 'woocommerce_output_content_wrapper_end', 25);
  }
}
add_action('wp', 'typek_remove_my_account_page_content');

This will remove the entire content of the My Account page, including the login form, registration form, and any other content added by plugins or custom code.

3. Removing the Login Form Using a Custom Plugin

If you don’t want to modify your theme’s functions.php file, you can also remove the login form in WooCommerce using a custom plugin. This method is recommended if you want to keep your changes separate from your theme and make them portable between different themes. Follow the steps below to create a custom plugin to remove the login form:

  1. Access your WordPress site’s files using an FTP client or the file manager in your hosting control panel.
  2. Navigate to the /wp-content/plugins/ folder.
  3. Create a new folder called typek-remove-login-form.
  4. In this new folder, create a new file called typek-remove-login-form.php.
  5. Open the typek-remove-login-form.php file in a text editor and add the following code:

<?php
/**
 * Plugin Name: Typek Remove Login Form in WooCommerce
 * Description: A custom plugin to remove the login form in WooCommerce.
 * Version: 1.0
 * Author: Typek
 */

// Typek_remove_login_form_in_woocommerce
function typek_remove_login_form_in_woocommerce() {
  if (is_account_page()) {
    remove_action('woocommerce_account_navigation', 'woocommerce_account_navigation');
    remove_action('woocommerce_before_customer_login_form', 'woocommerce_login_form');
    remove_action('woocommerce_before_customer_login_form', 'woocommerce_output_all_notices', 10);
  }
}
add_action('wp', 'typek_remove_login_form_in_woocommerce');

This code creates a custom plugin that includes the same PHP snippet we used in the functions.php method. By creating a custom plugin, you can easily deactivate or delete the plugin to restore the login form without modifying your theme’s files.

  1. Save the changes to the typek-remove-login-form.php file and upload the entire typek-remove-login-form folder to your server if necessary.
  2. Log in to your WordPress admin area and navigate to Plugins > Installed Plugins.
  3. Find the Typek Remove Login Form in WooCommerce plugin in the list and click Activate to enable the plugin.
  4. Visit your WooCommerce My Account page to confirm that the login form has been removed.

4. Conclusion

In this tutorial, we learned how to remove the login form in WooCommerce using a PHP snippet. We covered two different methods to achieve this: adding the PHP snippet to your theme’s functions.php file and creating a custom plugin. By following the steps outlined in this tutorial, you can easily remove the default WooCommerce login form and use a custom login solution or restrict access to your WooCommerce store to specific users. Remember to always backup your site’s files and database before making any changes, and test the changes on a staging site before applying them to your live site.

More traffic??

Are you looking for effective solutions to increase your Google search visibility?

Contact us and discover the full potential of online sales.

What our clients are say?

For me, they are a happiness factory. They managed my store’s website in such a way that users became happy, after which it turned out that the search engine was also happy. When the search engine became happy and started bringing me more happy customers, my business became equally happy 🙂

Matt

Great company, I recommend it to everyone. Services of the highest standard. Very good customer approach. I am very satisfied with their work.

Lukasz Szajny

Complete professionalism and an incredible commitment to their work. It’s worth emphasizing their hassle-free communication and full availability. I definitely recommend them.

Alexander