Back to Top

How to Create custom field in Woocommerce Products Admin Panel

To Create custom field in Woocommerce Products Admin Panel

WooCommerce is the most Widely used and well-known e-commerce plugin for WordPress.WooCommerce creates the products custom post type and sometimes you want own custom fields in Product type as per your site requirement.

WordPress provides plugin using which you can modify/create own custom fields in Admin panel and display on the front too.But today I am going to explain how to create custom fields into product data section by dynamically customizing WooCommerce using Action Hooks provided in Woocommerce plugin.

Let’s start step by step. Here I will explain for checkbox field. You can use same code for any field like Text, Textarea, Dropdown:

First of all, we will write action hook which will be used to display newly created field into the admin panel of product post type.The following code is used for same

Next, we will see how we can save newly created field information into WordPress database by using woo commerce action hook.

That’s it. You are done with adding custom fields into product page and save the value of that field into the database.Now, I will tell you how to add created field into product listing page and how to apply sorting on that field.

So, Here I am going to use one action hook of WordPress used for managing columns of particular post type and you need to add newly created field and then will call custom column action hook to get and display value of that field.

In this step, I will explain about to sort custom field into product listing page.First of all, will write filter hook which will add sorting action then code for sorting field by values.

That’s it. Place above code into your theme’s function.php file and run the code into browser :).

Also Read:

Cookie Free domain in WordPress
To create extra field into category or Custom Taxonomy in WordPress
Pagination when getting posts from category in WordPress

Hope this helps someone else out.As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (12)

  1. […] previous article, I have explained about To Create custom field in Woocommerce Products Admin Panel and today i continue with article with to add quick edit custom box in […]

  2. Hi,

    How i could do the same with input box but not a checkbox.

    Thanks for help

    1. Yes you do with input box also

  3. Thanks a lot. Just what I needed!!

  4. hi i am making an e-commerce site using woo commerce. i want to add customised field where in i can ask for user link to Facebook account near the product item. also it should be reflected during checkout, and later displays in my dashboard? so how can i add it? can u tell? you can mail me too

  5. Hi,
    I think the code don’t work with the biggest upgrade of WooCommerce. The “checkbox” option appears on the panel of administration of the product, but I can’t add description and nothing appears on the backend

    perhaps needs updating, it does not work in version 2.4.6

    1. Hello Tin,

      I will check code for version 2.4.6 and update soon.

    2. Hello Tin,

      I have checked code with version 2.4.6 of woocommerce and it is working fine.

      If you are facing issue,let me know your issue.

  6. ZhuChenGuang says:

    In the first step, you have missed a word in code.

    echo ”;

    echo ”;
    Fixed it as below;
    echo ”;

    echo ”;

  7. Is there a way to add JavaScript validation into the back-end? Or should validation be done in another fashion?

    For example, I added a custom text box to the product for a Commodity code value. Is there a way to validate and make sure the code is:

    a) Set
    b) A five digit value?

    Thanks!

  8. Is it possible to use this method to display the product custom post type author? I have a requirement to edit the author of the post and can’t seem to find a solution other than to edit the database. Any idea? Thank you, Rich

  9. Hi,

    is it possible to search for the custom column? I’ve added the post slug to the table and it would be great to add the slug for the search query.
    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

The Readers’ Poll – March 2013

Posted on 11 years ago

Bhumi