Typek – Blog

How to Remove the Order Notes in WooCommerce Using PHP Snippet

Introduction

In this tutorial, we will learn how to remove the Order Notes in WooCommerce using a PHP snippet. The Order Notes are additional notes that customers can add while placing an order on a WooCommerce store. While this feature can be helpful in some cases, it might not be necessary for all online stores. If you feel that the Order Notes section is not needed for your store, you can easily remove it by following the steps in this tutorial.

Prerequisites

Before proceeding with this tutorial, make sure you have the following:

  • A working WordPress website with WooCommerce installed and activated.
  • Access to your website’s files either via FTP or cPanel File Manager.
  • A code editor or a text editor to edit the PHP snippet.

Now that you have everything ready, let’s dive into the process of removing the Order Notes in WooCommerce using a PHP snippet.

Step 1: Create a Child Theme (Optional)

Before adding custom PHP code to your WooCommerce store, it is recommended to create a child theme. This ensures that your customizations will not be lost when you update your theme. If you already have a child theme, you can skip this step.

Follow these steps to create a child theme:

  1. Create a new folder in your themes directory, usually located at wp-content/themes/. Name the folder as your-theme-child, where “your-theme” is the name of your parent theme.
  2. Create a new file called style.css inside your child theme folder.
  3. Open the style.css file and add the following code:

/*
 Theme Name:   Your Theme Child
 Template:     your-theme
*/

Make sure to replace “Your Theme Child” with the name of your child theme and “your-theme” with the folder name of your parent theme.

  1. Create a new file called functions.php inside your child theme folder.
  2. Activate the child theme by going to Appearance > Themes in your WordPress dashboard and clicking the “Activate” button on your child theme.

Now that you have a child theme, you can add the custom PHP snippet to remove the Order Notes in WooCommerce.

Step 2: Add the PHP Snippet to Remove the Order Notes

Now that you have a child theme (or if you decided not to create one), you can add the PHP snippet to remove the Order Notes in WooCommerce. This code will disable the Order Notes field from the checkout page of your store.

Open the functions.php file of your child theme (or your active theme if you’re not using a child theme) and add the following code at the end of the file:


add_filter( 'woocommerce_enable_order_notes_field', 'typek_remove_order_notes' );
function typek_remove_order_notes( $enabled ) {
    return false;
}

This code adds a filter to the woocommerce_enable_order_notes_field hook, which is responsible for displaying the Order Notes field on the checkout page. The custom function typek_remove_order_notes() simply returns false, which disables the Order Notes field.

Save the changes to the functions.php file and upload it back to your server if you edited it locally. Now, when you visit the checkout page of your WooCommerce store, the Order Notes field should be gone.

Step 3: Test the Checkout Page

After adding the PHP snippet, it’s essential to test the checkout page to make sure the Order Notes field has been removed successfully. To do this, follow these steps:

  1. Visit your WooCommerce store and add any product to your cart.
  2. Go to the checkout page by clicking the “Checkout” button in the cart or the “View Cart” link in the top menu.
  3. Verify that the Order Notes field is no longer displayed on the checkout page. If the field is still visible, double-check your code and ensure the edited functions.php file was uploaded correctly.
  4. Complete a test order to ensure that the checkout process works smoothly without the Order Notes field. Make sure to test both the payment and shipping options.

Customizing the PHP Snippet (Optional)

If you want to customize the PHP snippet further or add conditions to remove the Order Notes only for specific cases, you can modify the typek_remove_order_notes() function.

For example, let’s say you want to remove the Order Notes field only for guest users. You can modify the function like this:


function typek_remove_order_notes( $enabled ) {
    if ( ! is_user_logged_in() ) {
        return false;
    }
    return $enabled;
}

This code checks if the user is logged in using the is_user_logged_in() function. If the user is not logged in (i.e., a guest user), the function returns false to disable the Order Notes field. Otherwise, it returns the original value of the $enabled parameter, which keeps the field enabled for logged-in users.

Conclusion

In this tutorial, you have learned how to remove the Order Notes field in WooCommerce using a PHP snippet. By following the steps provided, you can easily disable this feature for your online store and streamline the checkout process for your customers.

Remember that adding custom PHP code to your website can cause issues if not done correctly. Always make sure to back up your website and test your changes locally before applying them to your live site. If you encounter any issues, don’t hesitate to seek help from the WooCommerce community or a professional developer.

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