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

How to Create Default Attributes in WooCommerce

June 6, 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 allows you to add information to your products 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, for example, you create predefined Size and Color attributes and apply them to the different products. In WooCommerce, attributes are essential to:

  • Filter Products: Users can filter products based on a specific attribute, for example, medium-size jeans.
  • Create variable products: To create variations of a product, first, define its 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, this means that you can’t create size variations for them 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.

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 that the button is blocked, think that 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 that has a free version with basic features and 3 premium plans. This tool has thousands of active installations, and it’s one of the best in the market.

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 one of the premium plans.

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 modify the order of the attributes and place the attribute you want to set as the default first.

2) Manually via the WooCommerce Admin

You can also create default product attributes manually via 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 about how to create a child theme, check out our step-by-step guide.

This is important because if you change the parent theme’s files, the next time you update the theme, you will lose all your customizations. 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 if the meta_default_attributes exist so as not to run 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, then the script will add the first value of the available options in $new_defaults.

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

Then, it saves $new_defaults in the meta_default_attributes. This will be checked to 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.

Frequently Asked Questions

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

What Are Default Attributes in WooCommerce?

Default attributes are pre-selected options (like color or size) for variable products. They help speed up the buying process by auto-selecting a variation on page load.

Why Should I Set Default Attributes for a Product?

Setting defaults improves user experience and prevents confusion—especially when a product has multiple variations. It also ensures the “Add to Cart” button is available right away.

Can I Set Default Attributes for Existing Products?

Yes. You can edit any variable product in your WooCommerce dashboard, go to the “Variations” section, and choose defaults under the “Default Form Values” dropdown.

What Happens If I Don’t Set a Default Attribute?

Users will need to manually choose each variation before they can add the product to their cart. This can lead to a slightly slower or frustrating shopping experience.

Can I Set Different Defaults for Each Product?

Absolutely. Defaults are set individually for each product, allowing you to choose the most popular or recommended options based on your store’s needs.

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 an easy task.

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?