1. Home
  2. WC Vendors Pro
  3. How To
  4. Adding a Custom Field for Products

Adding a Custom Field for Products

Adding custom fields to the product edit form can be achieved in two ways.

  • Editing the template and inserting the form elements you need
  • Using Actions  (recommended option)

Field Examples

We have a complete form helper that provides a variety of different fields you can insert into your forms. Here are two example fields you can test.

Text Field

Text Area

Editing the template

This code will add a custom field to WC Vendor Pro’s add/edit form. Copy the template /plugins/wc-vendors-pro/templates/dashboard/product-edit.php to /themes/your-theme/wc-vendors/dashboard/product-edit.php and then add this code, including the opening/closing PHP tags anywhere on the form you want your custom field to be entered.

The sample code below will add a field called “Ingredients” with a text area to input the custom field. The field is then saved as “wcv_custom_product_ingredients” and will show up on the product page in the custom fields meta box.

You can change the wcv_custom_product_ingredients to be anything you like, as long as the meta key starts with wcv_custom _product or _wcv_custom_product_ — If you don’t start the meta key with that, it will be ignored. If the meta key has an underscore _ before it, it will be hidden on the product page in wp-admin, no underscore it will be shown in the Custom Fields meta box.

The code below goes in your product-edit.php template as outlined in the WCVendors Pro Setup Guide and you can override the template using the following guide: changing vendor templates. 

You need to know where you want the field to be displayed. We have commented the template file so you can see the different tabs

  • general
  • inventory
  • shipping
  • upsells and cross-sells (not recommended)
  • attributes (not recommended)
  • variations (not recommended)
  • product SEO

The following example will put the ingredients text area as the last field on the General Tab

Using Actions

The other options which do not require you to edit the template at all and instead hook into the template and output it. This is our recommended option as it ensures that you no longer have to keep your template overrides up to date and is completely upgrade safe.

We have actions for before and after every single field as outlined in our form helper help document under Actions. However here are the ones that are defined within the template itself that will add the field to the end of that tab

  • General Tab – wcv_product_options_general_product_data
  • Inventory Tab – wcv_product_options_inventory_product_data
  • Shipping Tab – wcv_product_options_shipping_data_panel
  • Upsells & grouping Tab – wcv_product_options_upsells_product_data
  • Attributes Tab – wcv_product_options_attributes_product_data
  • Variations Tab – wcv_product_options_variations_product_data
  • Product SEO Tab – wcv_product_seo_data

This example will output the ingredients text area as the last item on the General Tab

Display Custom Field on Single Product Page

This code will display the values on the single product page. Add this code to your theme’s functions.php file:

Please Note

A list of available field types can be found in the Form Helper documentation


Updated on December 1, 2019

Was this article helpful?