WooCommerce gives you two kinds of product attribute and only tells you they differ in where you create them. A global attribute is a real WordPress taxonomy named pa_<slug>, registered from a row in wp_woocommerce_attribute_taxonomies, with each value stored as a term. A custom attribute is a pipe-separated string inside one serialized postmeta blob on a single product, invisible to every taxonomy query in WordPress. Both render an identical dropdown on the product page, which is why stores pick the faster one and only discover the difference at the point where they want to filter by colour, build a facet, or report revenue by size. This guide sets up variable products the way that still holds at 500 SKUs, and converts the products that were built the other way.
What you’ll accomplish
- Create a global attribute and its terms, and understand exactly which database rows that produces.
- Build a variable product whose variations carry their own SKU, price, stock, image and shipping class.
- Generate variations deliberately instead of letting “create all combinations” produce a product nobody can edit.
- Convert an existing custom-attribute product to a global attribute without breaking the variation form.
- Leave behind two WP-CLI checks: variations per parent, and parents with no purchasable variation.
Prerequisites
WooCommerce 8.0 or later on WordPress 6.4+ with PHP 8.1+. The attribute data model described here has been stable since WooCommerce 3.0, so most of it applies to older stores too; the admin labels moved around between releases and that is called out where it matters.
Shell access with WP-CLI available as wp, run as the site user from the WordPress root. The wp wc subcommands go through the REST controllers and run capability checks, so they need a --user= flag naming an administrator — --user=1 is used throughout, substitute your own admin ID.
Confirm your table prefix before running any of the SQL below, and substitute it everywhere wp_ appears.
wp config get table_prefix
wp plugin get woocommerce --field=version
wp_
9.4.2
One schema note that saves confusion later: High-Performance Order Storage moves orders out of wp_posts. Products and variations are unaffected — they remain post types with postmeta in every WooCommerce release to date, so the queries here work on any store.
How it works
A variable product is not one record. It is a parent product post carrying the attribute definition, plus one product_variation child post per sellable combination, plus the taxonomy machinery that makes the values queryable.
Reading that left to right:
A row in wp_woocommerce_attribute_taxonomies holds attribute_name (color), attribute_label (Color), attribute_type and attribute_orderby. On every request, WordPress registers a taxonomy from that row with the pa_ prefix applied — pa_color. Values become terms in that taxonomy, and the parent product is linked to the terms it uses through wp_term_relationships, exactly like a category.
The parent also carries _product_attributes, a serialized array keyed by attribute name. For a global attribute the entry is name = pa_color, value = empty string, is_taxonomy = 1, plus is_visible and is_variation flags. For a custom attribute the entry is name = Color, value = Red | Blue | Green, is_taxonomy = 0 — the values live only in that blob.
Each variation stores its selection as postmeta: attribute_pa_color = red for a global attribute (the term slug, not the label), or attribute_color = Red for a custom one. An empty value means “Any”, and that variation matches every value of that attribute; a variation with a specific value wins over an “Any” variation when both could match.
That difference is the whole argument. Terms can be counted, filtered, joined and archived. A pipe-separated string inside a serialized blob can be displayed and nothing else. Layered navigation widgets, most faceted-search plugins, /wp-json/wc/v3/products?attribute=pa_color&attribute_term=…, and any report that groups by attribute all run against wp_term_relationships. Custom attributes are invisible to all of them.
The combinatorial ceiling. Every variation is one post plus roughly a dozen postmeta rows. Five sizes by eight colours by four finishes is 160 variations on one product — 160 posts before you have sold anything. WooCommerce also applies a filter, woocommerce_ajax_variation_threshold, defaulting to 30: at or below that count the whole variation set is embedded in the product page as JSON, and above it the front end fetches the matching variation over AJAX on each selection. So 30 is the point where behaviour changes, and a few hundred is where the admin variations panel — which pages through variations over repeated AJAX calls — becomes painful to use. Treat “how many combinations does this actually sell?” as a merchandising decision, not a data-entry one. If you are already past that line, the sibling guide on variation performance at scale covers the query and cache side.
Step-by-step
1. Create the global attribute. In the admin this is Products → Attributes. From the shell:
wp wc product_attribute create --name=Color --slug=color --type=select \
--order_by=menu_order --has_archives=false --user=1
Success: Created product_attribute 3.
Note the ID — you will need it, and has_archives=false keeps /color/red/ from becoming a public archive URL you did not plan to design.
2. Add the terms. The pa_color taxonomy is registered on init from the registry row, so it does not exist inside the request that created the attribute. Run the term creation as a separate command:
wp term create pa_color Red --slug=red
wp term create pa_color Blue --slug=blue
wp term create pa_color Green --slug=green
wp term list pa_color --fields=term_id,name,slug
+---------+-------+-------+
| term_id | name | slug |
+---------+-------+-------+
| 41 | Red | red |
| 42 | Blue | blue |
| 43 | Green | green |
+---------+-------+-------+
If wp term create reports an invalid taxonomy, the attribute row was not created or the object cache is holding a stale attribute list — flush it and retry.
3. Attach the attribute to the product and mark it used for variations. Set the product type to Variable product first, or the Variations tab will not appear. In the Attributes tab, add the existing Color attribute, select the terms this product sells, then tick both Visible on the product page and Used for variations. The second checkbox is the one that matters: without it the attribute renders as a specification row and no dropdown appears.
4. Generate variations deliberately. The Variations tab has a Generate variations button (older releases label it “Create variations from all attributes”). It produces the full Cartesian product of every attribute marked Used for variations, which is exactly the explosion described above — three attributes with modest term counts is a few hundred rows and an unusable edit screen. For anything past a couple of dozen combinations, add variations manually for the combinations you actually stock, or build the product from a CSV. The product CSV import guide covers the variation row format.
5. Set price, stock and shipping per variation. Every variation needs its own regular price. Stock is per variation only when you tick Manage stock? on that variation, which sets _manage_stock to yes and gives it its own _stock; leave it off and the variation inherits the parent’s stock status. Shipping class defaults to “Same as parent” and is stored as a product_shipping_class term on the variation post when you override it.
wp wc product_variation list 812 --user=1 \
--fields=id,sku,regular_price,stock_status,manage_stock
+------+-----------+---------------+--------------+--------------+
| id | sku | regular_price | stock_status | manage_stock |
+------+-----------+---------------+--------------+--------------+
| 4103 | TEE-RED-M | 34.00 | instock | 1 |
| 4104 | TEE-BLU-M | 34.00 | instock | 1 |
| 4105 | TEE-GRN-M | | instock | |
+------+-----------+---------------+--------------+--------------+
Variation 4105 has no price. It will not appear in the form at all — variation_is_visible() drops any variation whose price is an empty string, silently. This is the single most common “my variation disappeared” cause.
6. Set the default form values. At the bottom of the Variations tab, the Default Form Values row preselects a combination on page load; it writes _default_attributes on the parent. Use it when one combination is the obvious seller, and leave it empty when you want the shopper to make a conscious choice — a preselected out-of-stock default is a bad first impression.
7. Convert an existing custom-attribute product. This is the migration nobody documents. Four writes have to land together.
Create the attribute and its terms first, using steps 1 and 2 above, matching the term names to the values already in use. Then run the remap:
cat > /tmp/wc-attr-migrate.php <<'PHP'
<?php
$product_id = 812;
$old_key = 'color'; // sanitized name of the custom attribute
$taxonomy = 'pa_color'; // target global attribute
$product = wc_get_product( $product_id );
if ( ! $product || ! $product->is_type( 'variable' ) ) {
WP_CLI::error( "Product {$product_id} is not a variable product." );
}
if ( ! taxonomy_exists( $taxonomy ) ) {
WP_CLI::error( "{$taxonomy} is not registered yet - create the attribute, then re-run." );
}
// 1. Read the value every variation currently uses.
$values = array();
foreach ( $product->get_children() as $child_id ) {
$attrs = wc_get_product( $child_id )->get_attributes();
if ( isset( $attrs[ $old_key ] ) && '' !== $attrs[ $old_key ] ) {
$values[ $child_id ] = $attrs[ $old_key ];
}
}
// 2. Map each distinct value to an existing term ID.
$term_id_for = array();
foreach ( array_unique( $values ) as $value ) {
$term = get_term_by( 'name', $value, $taxonomy );
if ( ! $term ) {
WP_CLI::error( "No term named '{$value}' in {$taxonomy} - create it first." );
}
$term_id_for[ $value ] = (int) $term->term_id;
}
// 3. Link the parent to the terms and rewrite _product_attributes.
wp_set_object_terms( $product_id, array_values( $term_id_for ), $taxonomy );
$attributes = $product->get_attributes();
unset( $attributes[ $old_key ] );
$global = new WC_Product_Attribute();
$global->set_id( wc_attribute_taxonomy_id_by_name( $taxonomy ) );
$global->set_name( $taxonomy );
$global->set_options( array_values( $term_id_for ) );
$global->set_position( 0 );
$global->set_visible( true );
$global->set_variation( true );
$attributes[ $taxonomy ] = $global;
$product->set_attributes( $attributes );
$product->save();
// 4. Rewrite each variation: the meta key and the value both change.
foreach ( $values as $child_id => $value ) {
$variation = wc_get_product( $child_id );
$attrs = $variation->get_attributes();
unset( $attrs[ $old_key ] );
$attrs[ $taxonomy ] = get_term( $term_id_for[ $value ], $taxonomy )->slug;
$variation->set_attributes( $attrs );
$variation->save();
delete_post_meta( $child_id, 'attribute_' . $old_key );
}
WC_Product_Variable::sync( $product_id );
wc_delete_product_transients( $product_id );
WP_CLI::success( count( $values ) . ' variations remapped to ' . $taxonomy );
PHP
wp eval-file /tmp/wc-attr-migrate.php
Success: 3 variations remapped to pa_color.
The delete_post_meta() call is not optional. Saving the variation writes the new attribute_pa_color row but leaves the old attribute_color row in place, and a stale key confuses later imports and any code reading raw meta.
Validate it works
Count variations per parent and flag every variable product with no purchasable variation — a variation is purchasable only when it is published and _price is a non-empty string.
wp db query "SELECT p.ID, LEFT(p.post_title, 34) AS product,
COUNT(v.ID) AS variations,
SUM(CASE WHEN pm.meta_value IS NOT NULL AND pm.meta_value <> '' THEN 1 ELSE 0 END) AS priced
FROM wp_posts p
JOIN wp_term_relationships tr ON tr.object_id = p.ID
JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id AND tt.taxonomy = 'product_type'
JOIN wp_terms t ON t.term_id = tt.term_id AND t.slug = 'variable'
LEFT JOIN wp_posts v ON v.post_parent = p.ID AND v.post_type = 'product_variation' AND v.post_status = 'publish'
LEFT JOIN wp_postmeta pm ON pm.post_id = v.ID AND pm.meta_key = '_price'
WHERE p.post_type = 'product' AND p.post_status = 'publish'
GROUP BY p.ID
HAVING variations = 0 OR priced = 0
ORDER BY variations DESC"
ID product varia* priced
812 Classic Tee 3 2
1907 Canvas Print 0 0
Anything in that list is a live product page a shopper cannot buy from. Product 1907 has zero variations at all, which usually means the type was switched to variable and the variations were never created.
Then confirm the attribute is genuinely taxonomy-backed on one converted product:
wp post meta get 812 _product_attributes --format=json
wp post meta get 4103 attribute_pa_color
wp term list pa_color --object_ids=812 --fields=slug
{"pa_color":{"name":"pa_color","value":"","position":0,"is_visible":1,"is_variation":1,"is_taxonomy":1}}
red
red
blue
is_taxonomy is 1, value is empty, the variation holds a slug, and the parent is linked to the terms. That is the shape that filtering and reporting need. Finally, load the product page and select the combination whose variation is out of stock: WooCommerce keeps the option selectable, swaps in the availability message, and adds the woocommerce-variation-add-to-cart-disabled class to the button wrapper. It does not remove the option — unless backorders are enabled, in which case the button stays live on purpose.
Troubleshooting
The dropdowns do not render at all. Either the product type is not Variable product, or Used for variations is unticked. Check _product_attributes for is_variation: 1; if it is 0, the attribute is a specification row, not a variation axis.
A variation exists in the admin but never appears in the form. In order of likelihood: it has no price; it is saved as private rather than published; or woocommerce_hide_out_of_stock_items is set to yes and the variation is out of stock. Check wp option get woocommerce_hide_out_of_stock_items before you go looking for anything more exotic.
“Please select some product options before adding this product to your cart.” The submitted attribute value does not match any variation’s stored value. After a conversion this almost always means a leftover attribute_color row or a mismatch between the term slug and what the form posts. Compare wp post meta list 4103 --keys=attribute_pa_color against the value in the page source. The general causes are covered in add to cart not working.
Prices are wrong or the range is stale after an edit. The parent’s min/max price range is a synced value plus a transient. Run wp eval 'WC_Product_Variable::sync( 812 ); wc_delete_product_transients( 812 );' and reload. If filtering by attribute is also slow or wrong, regenerate the product lookup tables from WooCommerce → Status → Tools.
Two attributes with the same label. Creating a custom attribute called “Color” on a product that also uses global pa_color produces two dropdowns with the same label and no error. Search _product_attributes across the catalogue for non-taxonomy entries before assuming the store is clean.
When this is the wrong approach
Variable products model one product sold in variants of the same thing. If the options change what is shipped rather than which unit is picked — engraving text, a delivery date, a quantity-based configuration — you want product add-ons or a configurator, not 400 variations that exist only to represent free-text input.
If the options are genuinely independent products that happen to be bought together, use a grouped product. And if you are past a few hundred variations on a single parent because the catalogue is a matrix rather than a product, the honest answer is usually to split the parent into several products with fewer axes each. WooCommerce will let you create thousands of variations; the admin screen, the object cache and your merchandisers will all object first.
The full behaviour of the product data panel is documented in the WooCommerce variable product guide, and the WP-CLI commands used above are indexed at developer.wordpress.org/cli/commands.
If your catalogue is already large enough that the variations panel is timing out, read variation performance at scale next; if you are rebuilding the catalogue from a spreadsheet, the CSV import guide has the variation row format.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.