How to Create a New Custom Product Type in WooCommerce

In WooCommerce there you can choose from 4 default product types while adding a new product. But there are many cases where you want to add extra custom product type. If your requirement is similar to this, then here you can find the solution to it.

Custom Product Type WooCommerce Demo

As you can see the figure above at the bottom of the dropdown option of product data there is a new option called “Custom product”. Here I am going to create it and then add custom field data for this new product type. This code is tested with woocommerce version 3.4.3.

Let’s get started.

Create Custom Product Type

Add this code to your theme’s  functions.php  file. This will add the new custom product type field in dropdown option. But it will not have some basic product data tabs like “General” & “Inventory”.

Get Default Product Data Tabs for Our New Product Type

Now we will assign default product data tabs to our newly created custom product type. To do this we need to add few JS code to our admin footer. Here is the code to add next to your functions.php file.

Now we will have all default general pricing option and inventory. Here we need to note one thing that we have mentioned show_if_custom to our jQuery addClass function. In this section, you can put show_if_your_product_type, for your own custom product type.

Add Default Fields Tabs

Adding Custom Fields to General Tab of Our Product Type

After adding this code we can get our custom fields in general tab for our custom product type, as the picture below.

Add Custom Fields to Custom Product Type

Now we need to save the value of this field to our database, to do this we need to add next code snippet.

Now we have completed all customizations with our own custom product type.

Check for Custom Product Type on Front-end

After adding this product type we may need to check for our custom product type in WooCommerce template to show custom data specific to this custom product type.

Add this code snippet to your template files.

So this is it, from backend to frontend checking all code is included here in this tutorial. I have mentioned adding these codes to functions.php file of your theme. But more appropriate approach will be to make a plugin for it. To know more about plugin development see my tutorial for plugin development basics.

Here is the visual representation of this tutorial.

If this helps you or you have any more query let me know in the comment section below.

Happy Coding. 🙂

Leave a Reply

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