The Blog

Adding a WooCommerce Setting

I’d like to preface this by referencing a few resources that will definitely be of value to you if you’re interested in this topic. Firstly, read about the WooCommerce Settings API. Also, the Create a Plugin (for WooCommerce) document is pretty good too. Additionally, I wrote about how to add a section to the WooCommerce settings once upon a time – that’s pretty good too.

Regardless, if you’re still here, I’m going to take you through the process of adding a setting to WooCommerce. It’s going to be quick, simple, and hopefully easy to follow.

Let’s keep it really simple and try add a setting to WooCommerce > Settings > General.

Now, not only do I want to tell you how to do this, but I want to teach you how I’m doing it. You see, I’m not a savant. As I write this tutorial, I’ve opened up the WooCommerce source codeand am looking for where the general settings are defined.

A few moments later, I’ve found them under /includes/admin/settings/class-wc-settings-general.php. Now I’m looking for a filter – a hook – something to let me modify the general settings.

There, finally, I see it – woocommerce_general_settings. So there’s an array being passed through this filer that contains all of the general settings.

Now, if you’ve read my article on filters that I wrote a couple days ago and linked to just above, you probably know what I’m going to do next. If not, go read it.

I’ve now set up the code to hook into this filter, in another file (like a functions.php or a new plugin):

But that’s obviously not enough to do anything too exciting, so we want to get inside bryce_add_a_setting and add a setting! Let’s try out a text input:

Notice I also added in a ‘title’ before, and a ‘sectionend’ afterwards.

You can add a lot of different field types too, like a checkbox or a select input:

Beautiful, isn’t it?

So you can see it’s pretty easy to get started with adding settings to WooCommerce.

One last warning. Don’t just add settings for the sake of it. Settings should only be used when absolutely necessary, as I’ve written about before.

Introducing Metorik


A single dashboard unifying your store's orders, customers, and products, helping you understand your data and make more informed decisions.