“The selected product is invalid” and “isn’t a variation of” in WooCommerce: mismatched product IDs
WooCommerce shows these when an add-to-cart request names a variation that doesn't belong to the product it names. The cause is almost always a link, a form or a plugin sending the wrong pair of IDs.
In this article12 sections
An add-to-cart request for a variable product names two things: the product and the variation. This notice means they don’t belong together. The variation ID points at a variation of some other product, or at something that isn’t a variation at all. WooCommerce refuses rather than guess which one the shopper meant.
WooCommerce’s own product form always sends a matching pair. When you see this, something else built the request: a link, a theme form or a plugin.
The exact message#
The selected product is invalid.
The same failure can also read:
- The selected product isn’t a variation of Hoodie, please choose product options by visiting Hoodie.
Who sees it: Shoppers, as an error notice after an add-to-cart request that carries a variation ID. The longer wording is the one stores usually see, with the product name linked to its page. The short wording appears only when the product ID in the request isn’t a product at all. The Store API takes a single product or variation ID, so block-based buttons don’t produce either wording.
What WooCommerce checks#
When a request includes a variation_id, WooCommerce runs its option checks first: the option values, then any required options that are missing. Only then does it confirm the pair:
- The item loaded from
variation_idmust be a variation. - Its parent must be the product named in the request.
If either fails, WooCommerce loads the named product. If that works, the shopper sees “The selected product isn’t a variation of …” with a link to that product. If it doesn’t load, the shopper sees “The selected product is invalid.” WooCommerce’s own add-to-cart links and forms check that the product exists before they reach this point, so the short wording comes from code calling the cart directly.
Because the option checks come first, a mismatched pair can show “Invalid value posted for …” instead when the request also carries option values.
Causes and how to fix each one#
1. A link mixes up two products#
Hand-written add-to-cart links, ads, emails and buttons in page builders need both IDs to be right. A common slip is editing a link for a duplicated product: the duplicate gets new variation IDs, so changing only the product ID leaves the original’s variation in the link. Any link built from a spreadsheet with a column off by one does the same.
Check: Take the add-to-cart and variation_id numbers from the link. Open the product with the add-to-cart ID and look at its Variations tab: each variation’s header starts with its ID, such as #456. If the variation_id number isn’t in that list, this is the cause.
Fix: Rebuild the link with the variation’s real parent, in the form ?add-to-cart=PARENT_ID&variation_id=VARIATION_ID.
2. The variation ID isn’t a variation#
If a simple product’s ID ends up in variation_id, WooCommerce treats it as a variation that doesn’t belong and shows the longer wording. This happens with links where someone used a product ID in both places, or with plugins that send every product the variable way.
Check: Edit the product with the variation_id number by visiting post.php?post=ID&action=edit in your admin. If it opens a product whose Product data type is Simple product, this is the cause.
Fix: For a simple product, drop variation_id and use ?add-to-cart=PRODUCT_ID on its own.
3. A theme or plugin form sends the wrong variation#
Quick-view popups, sticky add-to-cart bars, bundle builders and pages with several product forms sometimes collect the variation from one product and the product ID from another. WooCommerce’s own variation script fills variation_id only from its own form, so this points to added code.
Check: Reproduce it from the exact button the shopper used, then try the same product’s own page. If only the theme or plugin button fails, that code is the cause. Health Check & Troubleshooting can switch it off for your session.
Fix: Update the theme or plugin, or report the product and variation IDs to its developer.
4. Custom code calls the cart with a bad product ID#
The short wording, “The selected product is invalid”, means the product ID didn’t load anything. WooCommerce’s own add-to-cart paths rule that out before calling the cart, so it comes from a plugin or a snippet calling the cart with an ID of 0, a deleted product or the wrong field.
Check: Search your theme’s functions file and custom plugins for add_to_cart( calls, and note where their first argument comes from.
Fix: Pass the variable product’s ID first and the variation’s ID third, or pass the variation’s ID alone as the first argument and let WooCommerce find the parent.
Quick reference#
| Cause | How to check | Fix |
|---|---|---|
| A link mixes up two products | Take the add-to-cart and variation_id numbers from the link. Open the product with the add-to-cart ID and look at its Variations tab: each variation's header starts with its ID, such as #456. If the variation_id number isn't in that list, this is the cause. | Rebuild the link with the variation's real parent, in the form ?add-to-cart=PARENT_ID&variation_id=VARIATION_ID. |
| The variation ID isn't a variation | Edit the product with the variation_id number by visiting post.php?post=ID&action=edit in your admin. If it opens a product whose Product data type is Simple product, this is the cause. | For a simple product, drop variation_id and use ?add-to-cart=PRODUCT_ID on its own. |
| A theme or plugin form sends the wrong variation | Reproduce it from the exact button the shopper used, then try the same product's own page. If only the theme or plugin button fails, that code is the cause. Health Check & Troubleshooting can switch it off for your session. | Update the theme or plugin, or report the product and variation IDs to its developer. |
| Custom code calls the cart with a bad product ID | Search your theme's functions file and custom plugins for add_to_cart( calls, and note where their first argument comes from. | Pass the variable product's ID first and the variation's ID third, or pass the variation's ID alone as the first argument and let WooCommerce find the parent. |
Reproduced on a test store#
We set up each case below on a clean WooCommerce 11.2.1 store on 6 November 2026 and recorded exactly what it showed.
| What we did | What WooCommerce showed |
|---|---|
| Two variable products, Hoodie and T-shirt, each with custom attribute Size: S, M, all variations priced 10. Logged out. Request ?add-to-cart=<Hoodie id>&variation_id=<T-shirt S variation id>. | The selected product isn't a variation of Hoodie, please choose product options by visiting Hoodie. |
| Same, adding &attribute_size=M. | Invalid value posted for Size |
| Hoodie plus a simple product priced 10. Request ?add-to-cart=<Hoodie id>&variation_id=<simple product id>. | The selected product isn't a variation of Hoodie, please choose product options by visiting Hoodie. |
| A must-use plugin that calls WC()->cart->add_to_cart( 999999, 1, <simple product id> ) on template_redirect, where 999999 is not a post. Load any page. | The selected product is invalid. |
| Request ?add-to-cart=<Hoodie id>&variation_id=<Hoodie S variation id>. | No message. The product was added to the cart. |
For developers#
WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation ) requires $variation_id to be a variation whose get_parent_id() equals $product_id. The safest call passes the variation ID as the product ID: the cart converts it and looks up the parent itself.
// Both of these add the same variation.
WC()->cart->add_to_cart( $variation_id, 1 );
WC()->cart->add_to_cart( wp_get_post_parent_id( $variation_id ), 1, $variation_id );If the variation has an Any option, pass that value in $variation, for example array( 'attribute_size' => 'M' ), or the cart stops earlier with “Size is a required field”. Request IDs can be rewritten with the woocommerce_add_to_cart_product_id filter.
Where this lives in WooCommerce 11.2.1:
includes/class-wc-cart.php,WC_Cart::add_to_cart: When a variation ID is given, the item must be a variation and its parent must be the product ID in the request. If the product ID doesn’t load a product, the short wording is used. Otherwise the longer one.includes/class-wc-form-handler.php,WC_Form_Handler::add_to_cart_action: Returns early when the add-to-cart ID isn’t a product, so links and forms reach the cart with a real product ID.includes/class-wc-form-handler.php,WC_Form_Handler::add_to_cart_handler_variable: Passes the add-to-cart ID and the posted variation_id to the cart unchanged.assets/js/frontend/add-to-cart-variation.js,VariationForm.prototype.onFoundVariation: WooCommerce’s own form only fills variation_id from that form’s own variations.
Related WooCommerce errors#
- Please choose product options by visiting Hoodie.
- Invalid value posted for Size
- Sorry, this product cannot be purchased.
Back to the WooCommerce error reference.
Frequently asked questions#
Why does a link that used to work now show this?
The link pairs a product with a variation that isn’t one of its own, often after the link was edited for a duplicated product. Rebuild it with the current IDs. If the variation was deleted instead, WooCommerce adds nothing and shows no notice at all.
How do I find a variation's ID?
Open the variable product, go to the Variations tab and look at each variation’s header. It starts with the ID, such as #456. A variation_id that isn’t in that list belongs to another product.
What is the right format for a variation add-to-cart link?
?add-to-cart=PARENT_ID&variation_id=VARIATION_ID, plus attribute_ values for any option the variation leaves as Any.
Why do I sometimes get "Invalid value posted" for the same link?
WooCommerce checks option values before it checks the pair of IDs. If the link also carries option values that don’t fit the variation, that notice appears first.
Does this happen with block-based Add to cart buttons?
No. The Store API takes one ID, the product’s or the variation’s, so there is no pair to mismatch.