When building an online store in WordPress, the WooCommerce plugin provides users with a wide range of product management and display options. While the product filters that come with WooCommerce are already very powerful, there are times when we need more customized filters, especially when we add custom fields to our products. In this article, we'll detail how to use custom fields to filter WooCommerce products, and show how to add custom fields to the page builder (Elementor or WPBakery) in which this function is implemented.
![图片[1]-使用自定义字段过滤WooCommerce产品:详细指南-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2024/08/2024081611083637.png)
What are custom fields?
Custom fields are a WordPress feature that allows users to add additional metadata to pages, posts, products, and more. ThesemetadataIt can be various types of content such as text, numbers, images, etc. Products in WooCommerce can also be extended with custom fields such as adding new product attributes, special descriptions, etc.
For example, byAdvanced Custom Fields (ACF) ProThe plugin's custom fields feature allows you to add new fields to products, such as "Material", "Brand", "Size", etc. These fields can be used as the basis for product filters, providing a more accurate product filtering experience for users. These fields can be used as the basis for product filters, thus providing users with a more accurate product filtering experience.
![图片[2]-使用自定义字段过滤WooCommerce产品:详细指南-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2024/08/2024081611091154.png)
Why use custom fields for product filtering?
There are many advantages to using custom fields for product filtering:
- Accurate screening: You can filter based on customized product attributes to enhance user experience.
- dexterity: You can set different filter conditions for different products to meet different business needs.
- Enhanced presentation: In combination with page builders such as Elementor or WPBakery, rich front-end presentation effects can be realized.
Implementation Steps
The following will detail how to filter WooCommerce products using custom fields, using the Elementor page builder as an example. For WPBakery, the steps are basically the same.
Step 1: Add product custom fields
Need to add custom fields to a product. Here we will use the ACF plugin to do this.
- Install and activate the ACF plug-in: Head over to the WordPress Plugin Library, search for and install the Advanced Custom Fields plugin, then activate it.
![图片[3]-使用自定义字段过滤WooCommerce产品:详细指南-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2024/08/2024081610540291.png)
- Creating a new field group::
- In the WordPress backend, navigate to the "Custom Fields" menu and click "Add Field Group".
- Name the field group (e.g. "Product Attributes") and add the required fields. For example, you can add a field named "Material" and select the type as "Text".
![图片[4]-使用自定义字段过滤WooCommerce产品:详细指南-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2024/08/2024081610452879.png)
- Associate field groups to products::
- In the Location option, set the field group to be displayed only on the product page.
- Save the field group.
Step 2: Define custom field values in the product
Next, the specific values of the custom fields need to be defined for each product.
- Edit product::
- Go to the All Products list to edit a product.
- On the edit page, you will see the custom field group you just created.
- Fill in the field values::
- Fill in the values of the custom fields according to the actual situation of the product. For example, if the field is "Material", you can fill in "Cotton", "Leather" and so on.
![图片[5]-使用自定义字段过滤WooCommerce产品:详细指南-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2024/08/2024081610471010.png)
- Save ChangesThe
Step 3: Setting up the page layout
Now, a layout needs to be created in the page builder that contains the product grid and grid filter elements.
- Create new page::
- In the WordPress backend, navigate to Pages > Add New Page.
- Choose to use Elementor or WPBakery to edit the page.
![图片[6]-使用自定义字段过滤WooCommerce产品:详细指南-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2024/08/2024081610583158.png)
- Add a two-column layout::
- Add a two-column layout to the page and adjust the width of the columns as needed. Typically, the columns for the product grid will occupy a larger width, while the filter columns will be relatively narrow.
Step 4: Add Product Grid Elements
![图片[7]-使用自定义字段过滤WooCommerce产品:详细指南-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2024/08/2024081611013422.png)
In the first column of the page, add a product grid element to display your product list.
- Add Product Grid::
- In Elementor, drag the product grid element to the first column.
- Configure settings for the product grid, such as selecting the types of products to display, sorting methods, paging settings, etc.
- Specify grid ID::
- In the product grid settings, specify a unique grid ID (e.g. "Gridtofilter"). This ID will be used to link the filter and the product grid in subsequent steps.
Step 5: Add the grid filter element
In the second column of the page, add a Grid Filter element to control the display of the product grid.
![图片[8]-使用自定义字段过滤WooCommerce产品:详细指南-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2024/08/2024081611004785.png)
- Add Grid Filter::
- In Elementor, drag the Grid Filter element to the second column.
- Again, specify the same grid ID ("Gridtofilter") as the product grid in the settings.
- Configuring Filter Options::
- When editing a grid filter, go to the Properties Repeater section and add a repeater item.
- In the Filter By field, select the previously added ACF field group (e.g., Product Attributes).
- In "Select Custom Fields", select a specific field (e.g. "Material").
- Add multiple filters::
- If there are multiple custom fields that need to be used as filters, you can go ahead and add repeater items and select a different custom field for each item.
Step 6: Publish the page and test it
Once setup is complete, you can publish the page and view the front-end results.
- Launch page::
- Save and publish the page.
- Preview and test::
- View the page on the front end and test that the filters are working as expected. Try selecting different filters to see if the product grid dynamically updates based on your selections.
Step 7: Add sorting function (optional)
If you wish to further enhance the user experience, you can add a grid sorting element.
- Adding a grid sort element::
- Adds a grid sort element to the page and associates it with the previous product grid element.
- Configuring Sorting Options::
- Select the fields you want users to be able to sort by (e.g. price, release date, etc.).
![图片[9]-使用自定义字段过滤WooCommerce产品:详细指南-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2024/08/2024080507113757.png)
summarize
With the above steps, have successfully filtered WooCommerce products using custom fields in your WordPress website. This method not only improves user experience, but also adds a high degree of customization and flexibility to your website. Whether it's a small online store or a large e-commerce platform, this method can help you better showcase your products and meet the diverse needs of your users.
Link to this article:https://www.361sale.com/en/16950/The article is copyrighted and must be reproduced with attribution.





















![表情[wozuimei]-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/themes/zibll/img/smilies/wozuimei.gif)
![表情[baoquan]-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/themes/zibll/img/smilies/baoquan.gif)

No comments