How to add custom field to product in WooCommerce - Phppot (2023)

vonVincy. Last modified on August 25, 2022.

WooCommerce is the best free ecommerce software. It is based on the WordPress platform. Setting up a shopping cart is easy with the WooCommerce platform.

In previous articles we have seen WooCommerce based code for the following utilities.

  • Stripe Payment Gateway-Integrationinto a shopping cart.
  • Contact form componentto send a product inquiry.

WooCommerce Product Showcase displays the information that matches customer demand. Sometimes preliminary details cannot convey everything and let the customer decide his fate.

This is something that needs to add additional information using custom field integration. WooCommerce plugins support adding custom fields to products from admin interface.

We will see these options below and their methods of use.

Why a WooCommerce store admin needs custom fields

Before adding custom fields to a product, learn why a WooCommerce store needs it.

Because some of the shops have oneroutine product gallerywith the usual data such as title, image and price. In this case, the custom fields are not required.

The list below shows the benefits of this custom field feature on aWooCommerceBusiness.

  • To add product metadata used to display additional information about products.
  • To allow customers to provide more specifications about the products to be purchased.
  • To add user-friendly interactive fields to save yourself the hassle of customization.
  • For adding promotions, offers, discounts and everything.
  • Assist end user to specify delivery date, time and place.
  • Apply taxes and shipping by toggling the custom toggle.

Types of custom field creation supported by WooCommerce plugins

The available onesWooCommerce-Pluginscan add two types of custom fields for products.

  1. Data Fields - The field accepts information to be displayed on the user interface.
  2. Add-on Fields - Fields that collect data from the user on the storefront.

1. Data Fields - The field accepts information to be displayed on the user interface

This custom field is for displaying more information besides the regular title, price and all. This helps show product metadata about features, version, rating and everything else.

For example a monitor to display additional information such as

MarkeDell
ModelDell 20H
screen size23
characteristicsHDMI, blur-free

2. Add-on Fields - Fields that collect data from the user on the storefront

This type of custom fields is all about creating options that the customer can interact with. It is intended to allow the addition of further specifications or customization to the targeted product.

It is for adding personalized information by customers when purchasing products. Example,

  • A box with multiple options to choose the size or color of a t-shirt.
  • A text box for collecting a brand name to be engraved on a purchased pen.

Methods to add custom fields are shown in WooCommerce

  1. Using WooCommerce plugins.
  2. Adding code to display custom fields for products.

Method 1: Using the plugin

We used three plugins to support adding custom fields to a product in a WooCommerce store. These come with advanced features and are also easy to set up.

  1. Advanced product fields for WooCommerce
  2. Product addons for WooCommerce
  3. Advanced custom fields

1. Advanced product fields for WooCommerce

This plugin is used to add additional fields to WooCommerce product page. It helps to embed product additional fields so customers can personalize the order.

(Video) eCommerce Website Set Up using WordPress WooCommerce

Check out the plugin details and requirements below.

execution4.5 or higher
Active installations20.000+
PHP-Version5.6 or higher
last update2 weeks ago

characteristics

  • The custom product field selected on the product page can be carried over to the cart and checkout pages. It is retained throughout the entire process until the order is received.
  • Frictionless backend product field builder with a seamless experience.
  • Possibility to add multiple prices to manipulate the base price of the products when choosing.
  • It supports all kinds of interactive fields with theShow option to hide.
  • It allows products and custom field mapping interfaces to control visibility.
  • Customization of WooCommerce tax number is possible.
  • Multilingual intranslatable topics.

steps to use

Download this pluginfrom the official WordPress repository. Then install and activate for the WooCommerce shop. If you are new to WordPress then see herehow to set up a plugin.

  1. From the WooCommerce admin menu, go to Product -> Add New.
  2. In the Product Data section, click Custom Fields.
  3. Configure the Field Group Layout settings. The position of the label or a field note, if any, should be specified. It also helps to mark a field as mandatory.
  4. Choose Add First Field or Add Field and specify field type, label and everything.
  5. Add conditional rules to add dependencies between fields to display.

This is the WooCommerce admin interface to add the custom fields for products. I added thoseSizeOption for the product as a ratio group.

How to add custom field to product in WooCommerce - Phppot (1)

This will show the added custom field as a radio button in the product frontend.

How to add custom field to product in WooCommerce - Phppot (2)

2. Product Addons for WooCommerce

This plugin clearly says the purpose by its name itself. Yes, it's about adding more additional fields so that the customer can interact with the shop to personalize the purchase.

A simple custom form builder allows creating a field group for the WooCommerce store pages. Check out the version and other details below.

WordPress-Version4.0 or higher
Active installations30.000+
PHP-Version5.6 or higher
Last updated at3 weeks ago

Download this pluginfrom the linked WordPress repository. The plugin provides aDrag and drop interfaceto create custom field groups for products.

characteristics

  • Can personalize the order.
  • It stores customer's personalized data via custom field added for products in backend.
  • Because builder helps to design a group of custom fields.
  • Allows more types of fields like text, number and email fields, combo boxes and all.
  • In the basic version it allows adding <p> and <h*> tags to show product meta in frontend.

steps to use

There are a few steps to add and display a custom field on a WooCommerce theme product page.

  1. Go toProdukte->Custom Product Addonsvia the WordPress admin menu.
  2. Add a new form to a custom product array and publish it.
  3. Go toProductsand open a new or edit the product field.
  4. Choose"Custom Product Options"of theproduct dataGroup.
  5. Review the form to add a mapping between custom fields and products.

See the following two screenshots to add custom fields and map them to the product.

How to add custom field to product in WooCommerce - Phppot (3)

How to add custom field to product in WooCommerce - Phppot (4)

Then the WooCommerce store will display the custom fields on the single product page.

How to add custom field to product in WooCommerce - Phppot (5)

3. Advanced Custom Fields

It supports full control over WordPress edit screen and custom form data.

WordPress-Version4.7 or higher
Active installations2+ million
PHP-Version5.6 or higher
last update6 days ago

The simple and intuitive plugin has powerful features and 30+ field types

characteristics

  • It offers powerful features to customize and add custom fields for the product
  • Good and simple backend interface to add custom field groups as needed.
  • Supports 30+ field types to differentiate more data from the standard custom product fields.

Steps to customize

Downloador install it via admin to enable this plugin before reading below steps.

  1. Add and customize the field group.
  2. Add form fields to the group.
  3. Add data for the custom fields on the product page.
  4. Display the product information in the frontend.

Step 1: Add and customize field group

Go toCustom Fieldsvia the admin menu. Add a new field group and specify the UI location and other settings.

It helps to set statuses and styles to add and display the custom fields on a product page. It manages the relative position and alignment of the field on the UI.

Fields can also be mapped to posts, products, pages, and more.

Step 2: Add form fields to the group

The Add Interface field allows the following data to be entered. For combo boxes, you will be prompted to enter multiple options for the loaded ones.

  • designation, name, type.
  • Field notes or help text.
  • Whether the field is required or not.
  • Placeholder and default value.
  • Content to be prepended or appended.
  • Character limit, rules.
  • Field wrapper classes or IDs.

Step 3 Add data for the custom fields based on products

If the custom fieldset is mapped to the Product Pages location, it will appear on the Add/Edit page.

Add the data for the custom fields that will be displayed on the WooCommerce product in the shop.

##Bild

Step 4: View the product information on the frontend

Then display the custom fields data on the product detail page on the frontend.

In this plugin we need to add a simple shortcode to display the custom fields on the product page.

The [acf field="<field ID or slug>"]speed dialused to display the custom field group.

There are a few features in WordPress to display the fields for a WooCommerce product.

<phpthe_field("<field ID or slug>");?>

or

<php$customFieldGroup = get_field("<Feld-ID oder Slug>");echo $customFieldGroup;?>

Method 2: Add custom fields programmatically

This is how we saw how to add custom product fields in a WooCommerce platform using plugins. If you want to implement the same without plugins, it's very easy with few steps.

These steps will render the custom fields on the WooCommerce product page. After collecting the user input on the product page, the custom code displays it on the cart page.

Steps to implement this method by adding custom code are given below.

  1. Add a custom field in the Product Data section of the WooCommerce admin.
  2. Save added custom field data to cart metadata.
  3. Display an input field on a product single page.
  4. Passing the values ​​on the cart and checkout pages.

Add this custom code in the function.php file of the active WordPress theme.

1. Adding custom fields in product data section

Create code to display custom fields in WooCommerce Product Data section. The woocommerce_product_options_general_product_data hook is used to call this code.

/* Produkt-Metafeld für den WooCommerce-Admin hinzufügen */Funktion woocommerce_custom_select_dropdown(){ $select = woocommerce_wp_select(array( 'id' => '_select_color', 'label' =>__('Select color', 'woocommerce'), 'options' => array( 'Black' => __('Black','woocommerce'), 'Blue' => __('Blue','wooocommerce'), 'Pink'=> __('Pink', 'woocommerce') ), ));}add_action('woocommerce_product_options_general_product_data', 'woocommerce_custom_select_dropdown');

This example adds a dropdown menu as a custom field for products. So it uses woocommerce_wp_select function to set the following parameters.

  • ID
  • label
  • Description
  • desc_type
  • options

There are similar functions to add other types of form fields. For example,

  • woocommerce_wp_textarea_input
  • woocommerce_wp_checkbox
  • woocommerce_wp_hidden_input

2. Save the user input in the custom fields in the cart metadata.

Then another action hook is added to save the custom field value in the product meta. This is called when saving the product details. It calls the woocommerce_process_product_meta action and hooks up the handler.

/* Benutzerdefinierte Felddaten für das Produkt speichern */function woocommerce_product_custom_fields_save($post_id){ $woocommerce_select_color_field = $_POST['_select_color']; if (!empty($woocommerce_select_color_field)) { update_post_meta($post_id, '_select_color', esc_attr($woocommerce_select_color_field)); }}add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');

3. Display an input field on a product single page

In this section, an additional HTML field is prepared if the product meta is not empty.

First, the admin selects and saves the product color option. Then this code adds a dropdown box on the single product page.

It reads the current product meta with the reference of the global post object. Then it retrieves the product meta by the custom field id.

On the WooCommerce product page, this custom field is added before the cart button. This is because the woocommerce_before_add_to_cart_button action has been hooked up to call this handler.

/* Add-on-Feld basierend auf dem gespeicherten benutzerdefinierten Feld anzeigen */function woocommerce_display_select_option_value(){ global $post; $product = wc_get_product($post->ID); $select_option_title_field = $product->get_meta('_select_color'); if ($select_option_title_field) { printf('<div><select name="color_option" class="input-text text"><option value="Default Color">Standardfarbe</option><option value="' . $select_option_title_field . '">' . $select_option_title_field . '</option> </select></div>', esc_html($select_option_title_field)); }}add_action('woocommerce_before_add_to_cart_button', 'woocommerce_display_select_option_value');

4. Display the selected option on the cart and checkout pages

The following filter hooks handle the functionality to display the selected custom option. It targets the cart and checkout pages to render the UI component.

This code is triggered when loading the cart item data. It calls the woocommerce_add_cart_item_data filter hook and displays the selected custom field value.

It inserts the data into the cart items array which will later be used in the checkout page UI.

/* Ausgewählte Option im Warenkorb anzeigen */function woocommerce_add_custom_field_item_data($cart_item_data, $product_id){ if (! empty($_POST['color_option'])) { $cart_item_data['select_field'] = $_POST['color_option'] ; } return $cart_item_data;}add_filter('woocommerce_add_cart_item_data', 'woocommerce_add_custom_field_item_data', 10, 2);

This is to parse the cart items array and display the custom field value on the checkout page.

It uses woocommerce_cart_item_name hook to make this change in checkout UI.

/* Ausgewählte Option im Checkout anzeigen */function woocommerce_cart_display($name, $cart_item, $cart_item_key){ if (isset($cart_item['select_field'])) { $name .= sprintf('<p>%s< /p>', esc_html($cart_item['select_field'])); } return $name;}add_filter('woocommerce_cart_item_name', 'woocommerce_cart_display', 10, 3);

Diploma

So we've seen both methods to add custom fields to products. It is possible with or without plugins to enable custom WooCommerce product fields.

I hope this article provides a basic knowledge in this area. Also, it can help you understand and repeat the steps to customize your store.

Leave a message

popular items

  • Ecommerce website set up with WordPress WooCommerce

↑ Back to top

FAQs

How do I add a custom field in WooCommerce checkout without plugin? ›

How to Add Custom Fields to WooCommerce Checkout Page
  1. Step 1: Define an Array of Fields on Checkout Page. ...
  2. Step 2: Add Custom Fields to WooCommerce Checkout Page. ...
  3. Step 3: Concatenate Fields as per Requirement. ...
  4. Step 4: Display Custom Fields on Order Page. ...
  5. Step 5: Display Fields on Account Page.
Jan 12, 2018

How do I add custom section and field in WooCommerce settings? ›

Log into your WordPress site and go to the WooCommerce->Settings page. Select the “Custom Fields” tab and click on the “Add Custom Field” button. Input the name of your custom field and select the type of field you want to add (e.g. text, select, checkbox, etc.).

How do I customize a field in WooCommerce? ›

Customize checkout fields with plugins
  1. Text – standard text input.
  2. Password – password text input.
  3. Textarea – a larger text field.
  4. Select – a dropdown box with options customers can choose from.
  5. Multi-select – a box that allows shoppers to select multiple options.
  6. Radio – a set of radio inputs that customers can choose from.
Jan 9, 2020

How do I use advanced custom fields in WooCommerce? ›

Installation
  1. Visit Plugins > Add New.
  2. Search for “Advanced Product Fields for WooCommerce”
  3. Activate the plugin from your Plugins page.
  4. Click on the new menu item WooCommerce > Product Fields and create your first Custom Field Group.

How do you add custom fields to WooCommerce products and subsequently through the order cycle? ›

  1. Step 1: Add Data in a Custom Session, on 'Add to Cart' Button Click. ...
  2. Step 2: Add Custom Data in WooCommerce Session. ...
  3. Step 3: Extract Custom Data from WooCommerce Session and Insert it into Cart Object. ...
  4. Step 4: Display User Custom Data on Cart and Checkout page. ...
  5. Step 5: Add Custom Data as Metadata to the Order Items.
Mar 1, 2022

What are custom fields for product? ›

Custom product fields are additional data points that can be added to products in an online store. These fields allow store owners to collect and display more information about their products beyond the basic details typically included (such as name, price, color, and description).

How do I add a custom field in WordPress without plugin? ›

Adding Custom Fields in WordPress

First, you need to edit the post or page where you want to add the custom field and go to the custom fields meta box. Next, you need to provide a name for your custom field and then enter its value. Click on the Add Custom Field button to save it.

How do I display custom field values in WordPress? ›

The default way to show custom fields in WordPress would be to:
  1. Open the single. php file or page. ...
  2. Find the_content function so you can list your custom field data after the actual content of the post or page.
  3. Use the get_post_meta function to fetch custom field values using their meta key then list them using PHP echo.
Dec 7, 2022

How do I enable custom fields in WordPress? ›

Enable custom fields in WordPress posts or pages
  1. When editing a page or post.
  2. Click on the three dots in the top right corner More Tools and Options.
  3. Click on Options at the bottom.
  4. Check the box to display Custom Fields and click Enable & Reload.

How do I get custom field value in WooCommerce checkout page? ›

To add a custom field to the WooCommerce checkout, select the field type in the Add New Field section, enter a label name and click on Add Field. WooCommerce checkout fields - Add a new field. Step 2. 🎉And it's done!

How do I add a custom field to a user registration form in WooCommerce? ›

How to Add Custom Registration Form Fields in WooCommerce
  1. Enable Customer Registration Option.
  2. Add Custom Code in Functions.php File.
  3. List of WooCommerce Form Fields.
  4. Validate Registration Form Fields.
  5. Edit WooCommerce Account Page.
  6. Add Required WooCommerce Form Field.
Mar 21, 2022

How do I customize a product in WooCommerce? ›

How to Customize the WooCommerce Product Page
  1. Step 1: Create the Single Product Template. ...
  2. Step 2: Choose a Pre-Designed Product Page Template, or build one from scratch. ...
  3. Step 3: Add the Product Widgets that will make up your page. ...
  4. Step 4: Preview the Product Page With Another Product. ...
  5. Step 5: Set the Conditions.
Apr 27, 2021

How do I add a custom field to a field catalog? ›

Go to 'Sales and Distribution > Basic Functions > Pricing > Pricing Control' and execute 'Define Condition Tables'. Select 'Conditions: Allowed fields' and enter 'ZZPSTYV' as a new entry. 5. Note: When you create the condition table Annn, you can now use the field ZZPSTYV as a key field.

How do I edit a custom field? ›

To edit a custom field:
  1. Select Settings ( ) > Issues.
  2. Under FIELDS, select Custom fields.
  3. Find the custom field you want to edit and select More ( ) > Edit details to update the following: The custom field name, which appears on issues. ...
  4. Modify the fields as needed and select Update.

How do I add advanced custom fields? ›

Link to heading#Method 1: Auto
  1. Log in to your WP install.
  2. From the Administration Panels, click on the Plugin Menu.
  3. Under Plugins, click the “Add New” sub menu.
  4. Search for “Advanced Custom Fields”
  5. Click the “Install Now” button on the ACF plugin (should be the first one)

Which function is used to add advanced custom field? ›

At the core of the Advanced Custom Fields plugin is the simple and intuitive API. Use functions like get_field() and the_field() to quickly build powerful templates.

How to add custom field to order in WooCommerce PHP? ›

First, to create a field, go to WooCommerce > Custom Order Fields. Click “Add Field” and begin creating your order field. The “label” is the field name, and will be displayed in the order details. The “description” will be displayed to the user upon hovering over the “?” symbol.

How do I add variations to WooCommerce products? ›

With attributes created and saved to add a variation, go to the Variations section in the Product data meta box.
...
Manually Add a Variation
  1. Select Add variation from the dropdown menu, and select Go.
  2. Select attributes for your variation. ...
  3. Edit any available data. ...
  4. Select Save changes.

How do you add variable products to your WooCommerce site step by step? ›

Variable Product in WooCommerce FAQs

Follow these steps to create a variable product in WooCommerce: In WooCommerce admin go to Products -> Attribures. Click the Add new attribute section and fill in the necessary fields. Tap the button Add attribute.

What is an example of custom field? ›

Examples of custom fields include data such as title, URL, name, timestamp, or any piece of data you want to define on a model.

What is the difference between The_field and Get_field? ›

the_field() automatically displays the field value on your page, where get_field() does not. Use get_field() when assigning field values to variables, or when manipulating the returned content in your code.

How do I add a custom field without plugins? ›

Step 1: Go to add a new post or edit a post, then click on Screen Options.
  1. The Edit Post screen in WordPress.
  2. Check the box "Custom Fields"
  3. The Custom Fields area.
  4. An example of saving the information about a product in custom fields.
  5. Add extra data into a custom field.
  6. Homepage after adding custom fields.
Jul 12, 2018

How to create custom field in PHP? ›

Scroll down to the Custom Fields module below your editor and click create new. Then enter in the content you want to display on the page or post you are using the custom field, in the value field. The name you enter must match the name in the function you added to your child themes functions. php file.

How to get custom field value in WordPress PHP? ›

To add a Custom Field, type in the Key (labeled “Name”) and Value, then click Add Custom Field. After it's added, you can delete or update it from buttons below the Key/Name: After you have used Custom Fields, the keys will form into a dropdown menu for easier selection.

Why custom fields are not showing WordPress? ›

If your WordPress site is missing the custom fields option under the 'Screen Options' menu, then you need to check if you have the Advanced Custom Fields (ACF) plugin active on your site. ACF is a very popular WordPress plugin that developers use to create custom meta boxes. ACF is running on over 1 million websites.

How do I add a custom field to a custom category in WordPress? ›

Link to heading#Adding fields
  1. From the Custom Fields admin screen, click the Add New button to create a new field group.
  2. Add the fields you would like to see when editing a Taxonomy Term.
  3. Under Locations, select the Taxonomy Term rule and choose the corresponding value to show this field group.

Where are custom fields stored in WordPress? ›

The ACF fields and groups are stored in the default wp-posts table with the post type acf-field-group for groups and acf-field for the fields. The acf-field post type are child posts of the acf-field-group post type.

Where can you add custom fields to the sales agreement product object? ›

Create Custom Fields for Sales Agreement Products and Schedules
  • In Object Manager, select Sales Agreement Product or Sales Agreement Product Schedule.
  • In Fields & Relationships, click New.
  • Select the data type for the new custom field, and then click Next.
  • Enter the field label, and click Next.

How do I add a custom field to a user? ›

Creating custom user fields
  1. In Admin Center, click People in the sidebar, then select Configuration > User fields.
  2. Click Add field.
  3. Select a field type, then enter a Display name.
  4. Verify that the field key is the value you want it to be. ...
  5. (Optional) Add a Description for the custom field.
Jan 3, 2023

How do I customize the product page code in WooCommerce? ›

You can follow these steps to edit the WooCommerce code,
  1. Log into your WordPress site files.
  2. Go to /wp-content/, then /plugins/.
  3. Open the /Woocommerce/ folder, then open /templates/ and finally /cart/.
  4. Select the file called cart. php and open it in your text editor.
Nov 22, 2022

How do I customize my WooCommerce product page for free? ›

To get started, install and activate the WooCommerce Extra Product Sorting Options plugin to your WordPress website. Once the plugin is activated, head over to Appearance > Customize > WooCommerce > Product Catalog. Here, you'll see a few different options to configure product sorting on your main shop page.

What are custom fields for products? ›

Custom product fields are additional data points that can be added to products in an online store. These fields allow store owners to collect and display more information about their products beyond the basic details typically included (such as name, price, color, and description).

How do I add variations to WooCommerce Products? ›

With attributes created and saved to add a variation, go to the Variations section in the Product data meta box.
...
Manually Add a Variation
  1. Select Add variation from the dropdown menu, and select Go.
  2. Select attributes for your variation. ...
  3. Edit any available data. ...
  4. Select Save changes.

How do I style a product in WooCommerce? ›

To create a new product page for WooCommerce, navigate to Templates–> Add New–> Landing page. Now select the Single Product Page option and create a new template. You will find a set of templates that are made for the WooCommerce product page. Select one and use the widgets in the list to design your product page.

How do I create a custom field? ›

Create a custom field in Project
  1. In Grid view, select Add column > New field.
  2. Choose a field Type: Important: A custom field's type cannot be changed after it's created. If a custom field is the wrong type, delete the field, then create it again using the correct type.
  3. Enter a Field name, then select Create.

How do I add a custom field to a purchase requisition? ›

Select Customize Purchase Order Form

Select the relevant tab at the top of the screen: Custom Fields, Disclaimer/Labels, Shipping Terms, Shipping Methods, PO PDF Labels and/or PO PDF Custom Fields. Select the + button located at the right-hand side of the screen.

How do I add a custom field to a purchase order? ›

Set up custom fields
  1. Go to Settings ⚙ and select Custom fields.
  2. Select Add field. ...
  3. Enter a name in the Name field.
  4. Select the All Sales forms or Purchase Order checkbox. ...
  5. (Optional) To show the custom field on printed and delivered forms, turn on Print on form. ...
  6. Select Save.

How do I activate custom fields? ›

Go to the custom fields meta box and select your custom field from the drop-down menu and enter its value. Click on the 'Add Custom Field' button to save your changes and then publish or update your post.

How to create advanced custom fields in WordPress without plugin? ›

Step 1: Go to add a new post or edit a post, then click on Screen Options.
  1. The Edit Post screen in WordPress.
  2. Check the box "Custom Fields"
  3. The Custom Fields area.
  4. An example of saving the information about a product in custom fields.
  5. Add extra data into a custom field.
  6. Homepage after adding custom fields.
Jul 12, 2018

Top Articles
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated: 03/11/2023

Views: 5585

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.