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

// Display Fields using WooCommerce Action Hook
add_action( 'woocommerce_product_options_general_product_data', 'woocommerce_general_product_data_custom_field' );

function woocommerce_general_product_data_custom_field() {
   global $woocommerce, $post;
   echo '
'; woocommerce_wp_checkbox( array( 'id' => 'product_checkbox', 'wrapper_class' => 'checkbox_class', 'label' => __('Checkbox for Product', 'woocommerce' ), 'description' => __( 'Description about checkbox', 'woocommerce' ) ) ); echo ''; }

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

// Save Fields using WooCommerce Action Hook
add_action( 'woocommerce_process_product_meta', 'woocommerce_process_product_meta_fields_save' );
function woocommerce_process_product_meta_fields_save( $post_id ){
    $woo_checkbox = isset( $_POST['product_checkbox'] ) ? 'yes' : 'no';
    update_post_meta( $post_id, 'product_checkbox', $woo_checkbox );

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.

//Add custom column into Product Page
add_filter('manage_edit-product_columns', 'my_columns_into_product_list');
function my_columns_into_product_list($defaults) {
    $defaults['product_checkbox'] = 'Checkbox for Product';
    return $defaults;

//Add rows value into Product Page
add_action( 'manage_product_posts_custom_column' , 'my_custom_column_into_product_list', 10, 2 );
function my_custom_column_into_product_list($column, $post_id ){
    switch ( $column ) {
    case 'product_checkbox':
        echo get_post_meta( $post_id , 'product_checkbox' , true );

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.

add_filter( "manage_edit-product_sortable_columns", "sortable_columns" );

// Make these columns sortable
function sortable_columns() {
    return array(
                'product_checkbox' => 'product_checkbox'

add_action( 'pre_get_posts', 'event_column_orderby' );
function event_column_orderby( $query ) {
    if( ! is_admin() )
    $orderby = $query->get( 'orderby');
    if( 'product_checkbox' == $orderby ) {

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?


  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.

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

How to backup MySQL database in PHP

Posted on 6 years ago


Constructor and Destructor in PHP

Posted on 7 years ago


how to shake a div using jQuery

Posted on 6 years ago


How to use Git init command

Posted on 2 years ago


Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – June 2015

Posted on 4 years ago


The Reader’s Poll – August 2014

Posted on 5 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago


The Readers’ Poll – August 2013

Posted on 6 years ago