WooCommerce is the cornerstone of many successful ecommerce stores, offering a robust platform for selling products online. One powerful feature is the ability to manage custom attribute values in WooCommerce, which are key in enhancing product descriptions and organizing product catalogs. Attributes like size, color, or material are vital for creating a smooth shopping experience and enabling product variations from a single listing.
While WooCommerce handles many features out of the box, managing attribute values beyond the default setup can become challenging. This is especially true when you want to display them differently on the front end, enable advanced filtering options, or retrieve them programmatically for custom functionality. This guide will show you exactly how to work with attributes effectively, manually, through custom code, or using helpful plugins.
Our goal is to give you a straightforward, step-by-step approach to handling product attributes, particularly custom ones, confidently, no matter your technical level. Whether managing your store or developing advanced features, you’ll find practical insights to make your WooCommerce store more flexible and user-friendly.
Understanding the Role of Custom Attributes in WooCommerce
Before diving into the “how-to,” it’s essential to understand a custom product attribute and why it’s so valuable.

What are Product Attributes in WooCommerce?
Product attributes are specific characteristics that describe your products. For example, a t-shirt might have a “Color” attribute with values like “Red,” “Blue,” and “Green.” A coffee mug might have a “Material” attribute with a value of “Ceramic.” These attributes serve two primary purposes:
First, they help customers find what they are looking for. They can be used in product filters on a shop page, allowing someone to quickly sort through all your products to find a specific size or color. This improves the overall user experience on your site.
Second, attributes are the foundation for creating product variations. If a T-shirt comes in different sizes and colors, you use attributes to define these options. Each combination of attributes, like a “Large, Blue” T-shirt, becomes a separate product variation with its price, SKU, and stock.
There are two main types of product attributes: global attributes and custom attributes. Global attributes are created once and can be used on any product in your store. Custom attributes are unique to a specific product. This article will focus on getting the values of these custom attributes.
Read More: How to Set a Featured Product in WooCommerce
Need Help Customizing WooCommerce for Your Clients?
Partner with WPServices for reliable white-label WordPress development and maintenance solutions.
The Difference Between Custom Attributes and Custom Fields
Many people confuse custom product attributes with custom fields (or post meta) in WordPress. While both can store extra data about a product, their intended use is different.
- Custom Attributes: These are designed for product characteristics that affect product variations or that you want to use for filtering. They are visible to customers by default and are part of the core WooCommerce functionality.
- Custom Fields: These store unique, private data about a single product. For example, a custom field might hold a supplier’s ID or an internal note. While you can display custom fields on the frontend with custom code, they are not intended for use in variations or for product filtering by default.
When you want to define characteristics that customers will interact with, an attribute is almost always the right choice.
Learn More: The Ultimate WooCommerce Setup: From Start to Finish
The Manual Method: Adding and Viewing Custom Attributes
You can easily add a custom attribute to a product without writing any code. This is the simplest way for store owners to use this functionality.
How to Add a Custom Attribute to a Product in WooCommerce
To add a custom attribute, follow these steps:
- Navigate to the Product Screen: Go to your WordPress dashboard, then to Products → All Products. Click on the product you want to edit.
- To access the Product Data Section, scroll to the Product Data box. This is where you configure all the details of your product.
- Go to the Attributes Tab: In the Product data section, click on the Attributes tab on the left side.
- Add a New Custom Attribute: In the dropdown menu, select Custom product attribute and click the Add button.
- Enter the Attribute Name and Values: A new section will appear. In the “Name” box, type the name of your attribute (e.g., “Sleeve Length” or “Material”). In the “Value(s)” box, enter the different values you want to use, separated by the pipe character (
|). For example:Short Sleeve | Long Sleeve.
- Save Your Changes: Once you have entered the attribute name and its values, click the Save attributes button.
These steps create a custom attribute that is specific to this product. The attribute values are now saved in the database.
How to Display Product Attributes on the Frontend
By default, WooCommerce automatically displays any custom attributes you add in the “Additional Information” tab on the product page. This section is located under the main product description. When a customer views the product, they can see a clear list of all the custom attributes and their values.
This is a perfect solution for simple custom attributes that don’t need any special styling. However, if you need to display a custom attribute in a different location or style, use a more advanced method.
Discover More: How to Change the “Add to Cart” Text in WooCommerce
Programmatic Approach: Getting Custom Attribute Values with Code
Accessing custom attribute values programmatically is essential for developers who need more control. You might need this to display a custom attribute in a different location on the product page, include it in a custom search filter, or use its value in other custom functionality.
Retrieving Custom Attribute Values for a Specific Product
The key to getting custom attribute values with code is to use the WC_Product object. This object holds all the data for a given product. You can use a simple code snippet in your theme’s functions.php file or a custom plugin.
This method takes the attribute’s name as a parameter and can be used to get the value of a specific custom attribute.
// Assuming you have the product ID, for example, from a query or loop
$product_id = 123; // Replace with your product's actual ID
$product = wc_get_product( $product_id );
// Retrieve the value of a custom attribute named 'material'
$material_value = $product->get_attribute('material');
// Check if the attribute exists and display its value
if ( $material_value ) {
echo 'The material of this product is: ' . $material_value;
} else {
echo 'No material attribute found for this product.';
}
This simple code block shows you how to access the value of a specific custom product attribute. You must use the exact attribute name entered in the product data section.
Looping Through and Displaying Multiple Attributes
What if you don’t know the exact names of all the custom attributes? You can get a list of all attributes and their values using the get_attributes() method. This returns an array of all global and custom attributes for the product.
// Assuming you have the product ID
$product_id = 123; // Replace with your product's actual ID
$product = wc_get_product( $product_id );
// Get all attributes for the product
$attributes = $product->get_attributes();
// Check if any attributes exist
if ( $attributes ) {
echo '<h3>Additional Product Characteristics</h3>';
echo '<ul>';
foreach ( $attributes as $attribute ) {
// Retrieve the attribute name
$attribute_name = wc_attribute_label( $attribute->get_name() );
// Get the value(s) of the attribute.
// For custom attributes, this will be a single string.
$attribute_value = $product->get_attribute( $attribute->get_name() );
// If it's a global attribute, get its terms
if ( $attribute->is_taxonomy() ) {
$attribute_value = implode( ', ', wc_get_product_terms( $product->get_id(), $attribute->get_name(), array( 'fields' => 'names' ) ) );
}
echo '<li><strong>' . esc_html( $attribute_name ) . ':</strong> ' . esc_html( $attribute_value ) . '</li>';
}
echo '</ul>';
}
This script loops through all the attributes on a specific product, getting each attribute’s name and value(s). The script also includes a check to handle both custom and global attributes, ensuring the correct data is retrieved and displayed.
How to Get Attribute Values for Variations
For a variable product, attributes are the foundation of each product variation. When a customer selects a specific variation, you might need to access its unique custom attribute value.
You can access variation data by getting all available variations for a product. This returns an array of all the product variations.
// Assuming you have the parent product object
$product = wc_get_product( $product_id );
// Get all available variations for the product
$available_variations = $product->get_available_variations();
// Loop through each variation
foreach ( $available_variations as $variation_data ) {
// Get the variation ID
$variation_id = $variation_data['variation_id'];
// Get the variation's WC_Product object
$variation_product = wc_get_product( $variation_id );
// Get the specific attribute value for this variation
// The attribute name must be prefixed with 'attribute_'
// Example: attribute_pa_color for a global attribute or attribute_size for a custom one.
$size_value = $variation_product->get_attribute('size');
// Display the variation details
echo '<h3>Variation ID: ' . $variation_id . '</h3>';
echo 'Size: ' . $size_value . '<br>';
echo 'Price: ' . $variation_product->get_price_html() . '<br><br>';
}
This code snippet is handy for developers who need to build custom frontend displays or for integrations that require specific product variation data. It correctly accesses the custom attribute value for each variation.
Advanced Techniques for Custom Attributes
Beyond simple display, custom attributes can power more advanced functionality on your site.
Filtering Products by Custom Attribute
Custom attributes are a powerful tool for product filtering. While WooCommerce’s native filtering widget works best with global attributes, you can programmatically filter products by a custom attribute. This involves using a custom WP_Query to find products that have a specific attribute value.
Here is an example of a custom query to find all products with a ‘Sleeve Length’ custom attribute equal to ‘Long Sleeve’.
$args = array(
'post_type' => 'product',
'posts_per_page' => 10,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_product_attributes',
'value' => 'a:1:{s:12:"sleeve-length";a:6:{s:4:"name";s:12:"Sleeve Length";s:5:"value";s:12:"Long Sleeve";s:8:"position";s:1:"0";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:0;}}',
'compare' => 'LIKE'
)
)
);
$products_query = new WP_Query($args);
if ( $products_query->have_posts() ) {
while ( $products_query->have_posts() ) {
$products_query->the_post();
// Display the product title or other details
the_title();
}
}
wp_reset_postdata();
Note: The meta_query value for custom attributes is a serialized array, which can be complex. For this reason, it is generally recommended to use global attributes for filtering and variations. However, this code example demonstrates that it is technically possible to query custom attributes.
Utilizing Custom Attribute Values in the Cart and Checkout
For a more robust ecommerce store, you might need to display a custom attribute on the cart or checkout page. This can be important for displaying a custom engraving or a specific product choice.
You can use a filter hook, such as woocommerce_get_item_data, to add custom attribute information to each item in the cart.
add_filter( 'woocommerce_get_item_data', 'display_custom_attribute_in_cart', 10, 2 );
function display_custom_attribute_in_cart( $item_data, $cart_item ) {
// Get the product object
$product = $cart_item['data'];
// Get the value of our custom attribute
$attribute_value = $product->get_attribute('engraving');
if ( ! empty( $attribute_value ) ) {
$item_data[] = array(
'key' => 'Engraving',
'value' => $attribute_value,
'display' => '',
);
}
return $item_data;
}
This function checks for a custom product attribute named “engraving” and displays its value in the cart item details. This provides your customers with all the necessary information about their order.
The Plugin Solution: Enhancing Attribute Functionality
Not everyone is comfortable writing code, and that’s where plugins come in. A well-chosen plugin can extend your store’s functionality, making managing custom attributes easier and providing a better shopping experience.

The Best Plugins for Managing and Displaying Custom Attributes
There are many great plugins available that can help you with product attributes. Here are a few examples:
- WooCommerce Attribute Swatches: This plugin converts the standard attribute dropdown menu into visually appealing swatches. For example, a color attribute can display a color box or an image instead of just text, significantly improving the user interface.
- Advanced Product Fields for WooCommerce: This plugin allows adding extra product options and custom fields with conditional logic. You can use it to create complex forms and dynamic pricing based on customer choices, which might include custom attribute values.
- WooCommerce Product Filters: These plugins provide advanced filtering widgets for your shop pages. They work seamlessly with global product attributes to help customers narrow their product searches, making the process faster and more intuitive.
Learn More: How to Use Elementor WooCommerce Builder
How Plugins Simplify the Process
Plugins abstract the complex code and give you an easy-to-use interface to manage everything. Instead of writing PHP, you can configure your custom attributes, their display, and their functionality through a simple set of menus in your WordPress dashboard. This saves a lot of time and reduces the risk of making errors in your code. They are perfect for store owners who want to enhance their site without the help of a developer.
Conclusion
Custom attribute values are a powerful component of any WooCommerce store. They are essential for managing product variations and improving the customer’s shopping experience. Understanding the different methods for retrieving these values, from the straightforward manual approach to the more complex programmatic solutions, can help you gain complete control over your store’s functionality.
Whether you add custom code to build a unique feature or install a plugin for a simple solution, this guide has provided you with the foundational knowledge you need. The ability to get custom attribute values in WooCommerce is a key skill for any developer or store owner looking to create a more dynamic and effective ecommerce store. Now, use your new knowledge to build something great for your store and customers.
FAQs About Custom Attribute Values in WooCommerce
How do I add custom attributes in WooCommerce?
You can add a custom product attribute by editing a product, navigating to the “Attributes” tab in the “Product data” section, selecting “Custom product attribute” from the dropdown, and clicking “Add.” Then, you enter the attribute name and its values.
How do I get attribute values in WooCommerce?
Programmatically, you can get attribute values using the wc_get_product() function to get the product object. Then, use the $product->get_attribute('your_attribute_name') method to retrieve a specific value or $product->get_attributes() to get all of them.
What is the difference between custom fields and attributes in WooCommerce?
Attributes are used for product characteristics that create variations or for filtering. Custom fields are for unique, one-off data not typically displayed to the customer or used for variations.
How do you edit attributes in WooCommerce?
To edit a custom attribute, you go back to the product’s “Attributes” tab, click on the attribute you want to change, make your edits, and then click the “Save attributes” button. For global attributes, you go to Products > Attributes in the WordPress dashboard.
What are attributes in WooCommerce?
Product attributes are descriptive characteristics of a product, such as size, color, or material. They help organize products and are essential for creating product variations to give customers more choices.


