Scale your business with our modular plugins.
Home » Blog » How to Create Default Attributes in WooCommerce

How to Create Default Attributes in WooCommerce

How to Create Default Attributes in WooCommerce
November 28, 2025||By German Rodrigo

Today, we’ll show you how to create default product attributes in WooCommerce with a plugin, manually from the WooCommerce dashboard, and programmatically via PHP. This is often overlooked, but it can have a significant impact on the conversion rates of your variable products.

What Are WooCommerce Attributes?

WooCommerce lets you add product information through attributes. You can apply these attributes to any new or existing products.

For example, common attributes are sizes and colors for clothing items, the operating system for mobile phones, and so on.

These attributes are global, meaning that instead of setting a size and color attribute for each new product, you create predefined Size and Color attributes and apply them to different products. In WooCommerce, attributes are essential to:

  • Filter Products: Users can filter products by a specific attribute, such as medium-size jeans.
  • Create variable products: To create product variations, first define the product’s attributes. Once you have the attributes, you can use them to make the different variations of the product. So, if you sell jeans, for example, you can’t create size variations unless you have created the size attribute for them.

Now, let’s gain a better understanding of why default attributes are so crucial for every WooCommerce store.

Why Create Default Product Attributes?

One of the first things we learned when we started our online store was the importance of creating default product attributes. In the beginning, our conversion rates weren’t very good and a lot of our users would tell us that the Add to Cart button was disabled.

However, every time we checked, everything was working well. The worst part is that we were losing a significant number of sales because many of those shoppers would never return to our store.

Why would they, if they couldn’t afford it?

It took us some time to realize that the problem was that we hadn’t set default product attributes in WooCommerce.

When You Should Use Default Attributes (and When You Should Not)

Setting default attributes can improve the product selection process. Still, they are not ideal for every scenario. Below is a clear breakdown to help merchants decide when default attributes add value and when they may create friction.

Use Default Attributes When:

  • Your product has a best-selling or most-popular variation that most customers choose
  • You want to speed up the buying workflow by preselecting a recommended option
  • You need to prevent users from landing on an unavailable or out-of-stock variation
  • You want to highlight a specific color, size, or style that converts the best
  • Your product variations do not drastically change price, appearance, or availability

Avoid Default Attributes When:

  • You sell customizable items and want customers to explore all options manually
  • Your variations have significant differences in price or appearance, and auto-selection may confuse buyers
  • You frequently update attributes or add new variations, which can break preset defaults
  • You want users to select every option to reduce misorders or size-related returns intentionally
  • Your product layout or theme may not clearly show that a variation has been preselected

Product Variations and Default Attributes

As you probably know, there are four types of products in WooCommerce: simple, variable, grouped, and external/affiliate.

Today, we’ll focus on the variable products and their default attributes.

When creating product variations in WooCommerce, it is recommended to set the default combination of those attributes. Otherwise, the ‘Add to Cart’ button on your product page will appear as disabled until the user selects the combination of attributes they want.

The problem is that many of them simply see the button is blocked, assume the page doesn’t work, and leave. That’s why if you have variable products in your WooCommerce store, creating default product attributes is a must.

WooCommerce default product attributes - Add to cart button disabled
Color and size don’t have default values, so the Add to Cart button is disabled

How to Create Default Product Attributes in WooCommerce?

There are three ways to create default product attributes in WooCommerce:

  1. With a plugin
  2. Manually via the WooCommerce admin
  3. Programmatically via PHP

If you’re not a developer, the easiest way is to use a plugin. With the PHP script, on the other hand, you can achieve the same thing with a bit of coding, without needing to install anything.

It’s important to note that you can get the same result with both methods, so choose the best one for you depending on your skills.

1) Create WooCommerce Default Product Attributes with a Plugin

The easiest way is to use a plugin to set default product attributes. For this guide, we’ll use Direct Checkout for WooCommerce.

It’s a freemium plugin with a free version offering basic features and 3 premium plans. This tool has thousands of active installations and is one of the best on the market. You can also get the free version plugin from the repository.

1. The first thing you have to do is install and activate the plugin. So, go to your WordPress dashboard > Plugins > Add New.

Then, search for ‘Direct Checkout for WooCommerce’, click ‘Install Now’, and when the installation process finishes, click ‘Activate’. Alternatively, you can visit this page and select either the free version or a premium plan.

2. Then, go to the WooCommerce section on the sidebar, and click the Direct Checkout option.

3. Go to the Products section and enable the last option, Add default attributes in variable products. Remember to save the changes.

That’s it! You’ve created default product attributes with Direct Checkout for WooCommerce! Now, the first attribute of each product will be selected by default, and this will be applied to all your variable products.

Therefore, if you wish to change the default attributes, you must reorder the attributes and place the attribute you want to set as the default first.

2) Manually via the WooCommerce Admin

You can also manually create default product attributes in the WooCommerce dashboard. This method is quick and easy, but can be time-consuming if you have a large number of products. If that’s your case, we recommend using the Direct Checkout plugin or the PHP script described in Section 3.

  1. To set default attributes manually, first, go to the WooCommerce dashboard, then navigate to Products, and click on your variable product.
  2. Then, select Variable product from the Product data dropdown.
  3. After that, under Variations, select the Default Form Values. Those are the attributes that will be selected by default for that product.

That’s it! You’ve manually created default product attributes. Now, when a shopper visits the variable product page, it will display the attributes you selected by default, and the “Add to Cart” button will be enabled.

WooCommerce default product attributes - Add to cart button enabled
Color and size with default values, so the Add to Cart button is enabled

Keep in mind that you have to set the default attributes for each variable product that you have. That’s why, if you have many products, we recommend using the Direct Checkout plugin or the PHP script that we’ll describe below.

3) Create Default Products Programmatically (PHP)

If you don’t want to install any plugin on your site and you have some coding skills, you can create WooCommerce default product attributes programmatically with a bit of PHP.

TIP: Create a child theme

Before you begin, we recommend creating a child theme. If you don’t have one, simply install any plugin that you like or code it yourself.

For more information on creating a child theme, check out our step-by-step guide.

This is important because if you change the parent theme’s files, you will lose all your customizations the next time you update the theme. However, if you modify the child theme, your changes won’t be overridden by the theme’s new version.

Now that you’ve installed the child theme, let’s get into it.

PHP Script

To set the default variation programmatically in WooCommerce, you’ll need to modify the functions.php file. Simply go to wp-content/yourtheme/functions.php on your child theme.

Here, we’ll show you the full code, and then we’ll explain its main parts. So the full PHP script to create WooCommerce default product attributes programmatically is the following:

add_action('woocommerce_before_single_product_summary', 'quadlayers_product_default_attributes');
function quadlayers_product_default_attributes() {
      global $product;
      if (!count($default_attributes = get_post_meta($product->get_id(), '_default_attributes'))) {
        $new_defaults = array();
        $product_attributes = $product->get_attributes();
        if (count($product_attributes)) {
          foreach ($product_attributes as $key => $attributes) {
            $values = explode(',', $product->get_attribute($key));
            if (isset($values[0]) && !isset($default_attributes[$key])) {
              $new_defaults[$key] = sanitize_key($values[0]);
            }
          }
          update_post_meta($product->get_id(), '_default_attributes', $new_defaults);
        }
      }
    }

Now, let’s break it down.

The Hook

We use the hook woocommerce_before_single_product_summary. This action hook runs before the page loads, allowing you to add logic before the user sees it.

add_action('woocommerce_before_single_product_summary', 'quadlayers_update_product_default_attributes');

Check Default Attributes

Then we check whether meta_default_attributes exist to avoid running the script twice.

if (!count($default_attributes = get_post_meta($product->get_id(), '_default_attributes'))) {
$new_defaults = array();

Attributes

After that, we get the whole array of attributes

$product_attributes = $product->get_attributes();
if (count($product_attributes)) {

And then we iterate over that array of attributes.

foreach ($product_attributes as $key => $attributes) {
$values = explode(',', $product->get_attribute($key));

We get the first value of each attribute.

if (isset($values[0]) && !isset($default_attributes[$key])) {

If the attribute doesn’t have a value, the script will add the first available value from $new_defaults.

$new_defaults[$key] = sanitize_key($values[0]);
}
}

Then, it saves $new_defaults in the meta_default_attributes. This will prevent the script from running twice.

update_post_meta($product->get_id(), '_default_attributes', $new_defaults);
}
}
}

Troubleshooting Default Attribute Issues in WooCommerce

Even after setting default attributes, you may encounter minor issues. Here’s how to fix common issues:

  • Default Variation Not Showing on Product Page → Go to Products > Edit Product > Variations and make sure a variation exists that matches your selected defaults.
  • “Add to Cart” Button Not Appearing → This often means WooCommerce can’t find a matching variation. Recheck that your default attributes match a valid variation combo.
  • Changes Not Reflecting on the Frontend → Clear your WordPress cache, browser cache, and regenerate CSS if using a caching plugin or theme builder.
  • Variation Prices Not Updating Automatically → Try refreshing permalinks by visiting Settings > Permalinks and clicking Save Changes without editing anything.
  • Theme or Plugin Conflicts → Temporarily switch to a default theme like Storefront and disable non-WooCommerce plugins to identify conflicts.

Common Mistakes to Avoid When Setting Default Attributes

Many store owners unintentionally create confusion or display issues when assigning default attributes, so it is important to avoid the most common pitfalls.

  • Selecting a variation that is out of stock immediately triggers an unavailable message
  • Using default attributes that do not match the actual variation combinations configured in the product
  • Preselecting an option that significantly raises the price and surprises customers during checkout
  • Forgetting to update default selections after adding or removing attribute terms
  • Setting defaults for products that rely on customer customization, reducing engagement with other variations
  • Allowing caching plugins to store outdated variation data, which prevents the correct default from loading
  • Using inconsistent attribute naming, leading to mismatches between global and product-level attributes

Frequently Asked Questions

Now, let’s see some of the frequently asked questions and answers.

How do default product attributes work in WooCommerce

Default product attributes act as preselected options for variable products so customers see a preferred size, color, or variation when the product page loads, improving both UX and conversions by reducing unnecessary clicks.

Can I set different default attributes for each product

Yes, each variable product can have its own default attribute combination, allowing you to highlight the variation you want customers to notice first, such as the most popular size or the version with the best stock levels.

Why don’t my default attributes show on the product page

This usually occurs when the chosen default attribute combination doesn’t match an existing product variation, so WooCommerce fails to preselect it; updating attributes and ensuring a matching variation resolves the issue.

Do default attributes affect product SEO

They do not directly influence search rankings, but they can indirectly help by improving user interaction and reducing bounce rates, since customers see a ready-to-buy option immediately.

Is it possible to set global default attributes for all products

WooCommerce doesn’t support global defaults out of the box, but you can achieve this using code snippets or attribute-management plugins that automate default selections across multiple products.

How can I reset or remove default attributes from a product

Simply edit the variable product, locate the default form values panel, and change the attribute back to “No default” so WooCommerce stops preselecting any variation.

Do default attributes affect inventory or stock management

No, setting a default variation doesn’t change inventory behavior; it only influences what customers see first, while each variation continues to track stock independently.

Conclusion

All in all, not setting default attributes for variable products can negatively impact your conversion rates and result in lost sales. The Add to Cart button will appear as disabled, so users may think that they can’t buy and leave.

The good news is that adding default attributes is easy.

If you don’t have coding skills, you can use Direct Checkout for WooCommerce and add the default product attributes with a couple of clicks.

Additionally, if you don’t have many products, you can do it manually via the WooCommerce dashboard. On the other hand, if you prefer to do it programmatically, you can set the default attributes with a bit of coding.

If you want more information about how to improve your WooCommerce site programmatically, you can have a look at our guides about how to add to cart function and to implement AJAX add to cart on your site.

Which of these methods are you going to use?

Let us know your thoughts in the comments section below!

15 comments

  • The manual code doesn’t work anymore. Any suggestions?

  • @Brenda, couldn’t you add another variation that costs a bit more, call it “manual configuration”, and set that as default? Then you can get back to those buyers about the configuration, and you can have your expenses covered by adding to the price.

  • Thank you so very much! I was desperate for this information, I just hadn’t seen the possibility to set defaults in the Variable product field. I’m working towards opening my shop and thought it can’t be good not to have a premade setting. Very glad I found your site.

  • Hello! We want our default to stay “no default product variation” but every few weeks, all of our variable products end up with default variations (I believe it’s the first in each attribute list, but I didn’t check every single product to confirm that). Because of the nature of the products we sell, it’s causing issues — customers keep buying codes for the wrong product because they don’t bother to change away from the default — we want to force them to make a selection. Any insight? We cannot find any pattern to why this is occurring. (note we use method 2 from above, Manually via WooCommerce admin)

  • Thank for your php code.
    It working for me. (Woodmart Theme).
    You should clear cache and restart sevice..

  • Thanks but the PHP code is not working. Please update the code.

    • Hi Samuel, to help you out, could you please tell us:
      1) What error do you get?
      2) What theme are you using?
      3) Have you tried using Storefront?

  • Hello,
    i just add product variations swatches plugin but
    the page continues was showing me and the others attributes maybe by default theme.
    what can i do to change the default?

  • Hi Zachary,
    What would be the best attributes to add to a handmade jewelry website?
    Thank you.

  • Hey Zachary. Hi
    Of course, few database requests means more performance, but WP and WC are constantly retrieving and updating values into the database.
    This is the way a website works

  • I haven’t dove into the update_post_meta() function too deeply, but I know it performs a database write. If it does this every time, even if the value hasn’t changed, this would cause a DB write on every page load, which is a terrible performance and resource usage oversight. I would find a better way to change this value on the fly, or set it at save/import time.

  • Hi,

    I just tried to integrate it in my child theme, unfortunately it seems to have a problem with Astra Pro theme too. No standard variant is set to the products.

    I’m also looking for a solution how I can set the default size of my clothes to ‘medium’ as pre-selected attribute, if available. Not enough coding background to get it done myself at the moment.

  • Hello,

    I’ve tried this code but it doesn’t seem to be working with the latest WP&Woo – does it need updating?

    And more importantly, is it possible to amend this snippet so that it only selects the first available option from one only attribute? For example, if you have size and colour attributes, would it be possible to select only first size option (and not select anything from the colour)?

    Thanks!
    Thanks!

    • A

      Hello mate
      Please check this with the storefrom theme
      Some themes could be incompatible with this hooks

Leave your comment

Log into your account
Forgot your password?