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.
- Data Fields - The field accepts information to be displayed on the user interface.
- 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
Marke | Dell |
Model | Dell 20H |
screen size | 23 |
characteristics | HDMI, 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
- Using WooCommerce plugins.
- 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.
- Advanced product fields for WooCommerce
- Product addons for WooCommerce
- 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.
Check out the plugin details and requirements below.
execution | 4.5 or higher |
Active installations | 20.000+ |
PHP-Version | 5.6 or higher |
last update | 2 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.
- From the WooCommerce admin menu, go to Product -> Add New.
- In the Product Data section, click Custom Fields.
- 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.
- Choose Add First Field or Add Field and specify field type, label and everything.
- 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.
This will show the added custom field as a radio button in the product frontend.
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-Version | 4.0 or higher |
Active installations | 30.000+ |
PHP-Version | 5.6 or higher |
Last updated at | 3 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.
- Go toProdukte->Custom Product Addonsvia the WordPress admin menu.
- Add a new form to a custom product array and publish it.
- Go toProductsand open a new or edit the product field.
- Choose"Custom Product Options"of theproduct dataGroup.
- 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.
Then the WooCommerce store will display the custom fields on the single product page.
3. Advanced Custom Fields
It supports full control over WordPress edit screen and custom form data.
WordPress-Version | 4.7 or higher |
Active installations | 2+ million |
PHP-Version | 5.6 or higher |
last update | 6 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.
- Add and customize the field group.
- Add form fields to the group.
- Add data for the custom fields on the product page.
- 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.
- Add a custom field in the Product Data section of the WooCommerce admin.
- Save added custom field data to cart metadata.
- Display an input field on a product single page.
- 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? ›
- Step 1: Define an Array of Fields on Checkout Page. ...
- Step 2: Add Custom Fields to WooCommerce Checkout Page. ...
- Step 3: Concatenate Fields as per Requirement. ...
- Step 4: Display Custom Fields on Order Page. ...
- Step 5: Display Fields on Account Page.
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? ›- Text – standard text input.
- Password – password text input.
- Textarea – a larger text field.
- Select – a dropdown box with options customers can choose from.
- Multi-select – a box that allows shoppers to select multiple options.
- Radio – a set of radio inputs that customers can choose from.
- Visit Plugins > Add New.
- Search for “Advanced Product Fields for WooCommerce”
- Activate the plugin from your Plugins page.
- Click on the new menu item WooCommerce > Product Fields and create your first Custom Field Group.
- Step 1: Add Data in a Custom Session, on 'Add to Cart' Button Click. ...
- Step 2: Add Custom Data in WooCommerce Session. ...
- Step 3: Extract Custom Data from WooCommerce Session and Insert it into Cart Object. ...
- Step 4: Display User Custom Data on Cart and Checkout page. ...
- Step 5: Add Custom Data as Metadata to the Order Items.
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.
- Open the single. php file or page. ...
- Find the_content function so you can list your custom field data after the actual content of the post or page.
- Use the get_post_meta function to fetch custom field values using their meta key then list them using PHP echo.
- When editing a page or post.
- Click on the three dots in the top right corner More Tools and Options.
- Click on Options at the bottom.
- Check the box to display Custom Fields and click Enable & Reload.
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? ›
- Enable Customer Registration Option.
- Add Custom Code in Functions.php File.
- List of WooCommerce Form Fields.
- Validate Registration Form Fields.
- Edit WooCommerce Account Page.
- Add Required WooCommerce Form Field.
- Step 1: Create the Single Product Template. ...
- Step 2: Choose a Pre-Designed Product Page Template, or build one from scratch. ...
- Step 3: Add the Product Widgets that will make up your page. ...
- Step 4: Preview the Product Page With Another Product. ...
- Step 5: Set the Conditions.
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? ›- Select Settings ( ) > Issues.
- Under FIELDS, select Custom fields.
- 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. ...
- Modify the fields as needed and select Update.
- Log in to your WP install.
- From the Administration Panels, click on the Plugin Menu.
- Under Plugins, click the “Add New” sub menu.
- Search for “Advanced Custom Fields”
- Click the “Install Now” button on the ACF plugin (should be the first one)
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? ›...
Manually Add a Variation
- Select Add variation from the dropdown menu, and select Go.
- Select attributes for your variation. ...
- Edit any available data. ...
- Select Save changes.
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.
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? ›- The Edit Post screen in WordPress.
- Check the box "Custom Fields"
- The Custom Fields area.
- An example of saving the information about a product in custom fields.
- Add extra data into a custom field.
- Homepage after adding custom fields.
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? ›- From the Custom Fields admin screen, click the Add New button to create a new field group.
- Add the fields you would like to see when editing a Taxonomy Term.
- Under Locations, select the Taxonomy Term rule and choose the corresponding value to show this field group.
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? ›- 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.
- In Admin Center, click People in the sidebar, then select Configuration > User fields.
- Click Add field.
- Select a field type, then enter a Display name.
- Verify that the field key is the value you want it to be. ...
- (Optional) Add a Description for the custom field.
- Log into your WordPress site files.
- Go to /wp-content/, then /plugins/.
- Open the /Woocommerce/ folder, then open /templates/ and finally /cart/.
- Select the file called cart. php and open it in your text editor.
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? ›...
Manually Add a Variation
- Select Add variation from the dropdown menu, and select Go.
- Select attributes for your variation. ...
- Edit any available data. ...
- Select Save changes.
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? ›- In Grid view, select Add column > New field.
- 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.
- Enter a Field name, then select Create.
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.
- Go to Settings ⚙ and select Custom fields.
- Select Add field. ...
- Enter a name in the Name field.
- Select the All Sales forms or Purchase Order checkbox. ...
- (Optional) To show the custom field on printed and delivered forms, turn on Print on form. ...
- Select Save.
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? ›- The Edit Post screen in WordPress.
- Check the box "Custom Fields"
- The Custom Fields area.
- An example of saving the information about a product in custom fields.
- Add extra data into a custom field.
- Homepage after adding custom fields.