WooCommerce: Add Variation to cart leads to 400 Error

Hey there,

I am facing a problem when trying to add a Product to cart which is a variable product.

Whenever I trigger the button with the action “add to cart” applied it results in a 400 Error saying:

cc-woocommerce.min.js?ver=1.3.4.6:1 
POST https://example.com/wp-json/wc/store/v1/cart/add-item?id=378&quantity=1 400 (Bad Request)
(anonymous) @ cc-woocommerce.min.js?ver=1.3.4.6:1
cc_woo @ cc-woocommerce.min.js?ver=1.3.4.6:1
(anonymous) @ ccers.min.js?ver=1.3.4.6:1

The Payload also seems to be ok to me:

{
  "variation": [
    {
      "attribute": "pa_flex-boot-groesse",
      "value": "85"
    },
    {
      "attribute": "pa_farbe-neopren-gaiter",
      "value": "cognac"
    },
    {
      "attribute": "pa_farbe-backstrap",
      "value": "cognac"
    }
  ]
}

It is only happening on one product. It’s a product which is relatively complex (auto-variations would added up to 1600+ Variants), but we decided to go an easier way so we now have only 14 Variations on that product. It seemed to be ok, and we used that logic in adding variations within other products (which can be added to the cart very well), but on that specific product it doesn’t work for some reason.

The price get’s calculated correctly when choosing the variants, so it seems that everything is working out well, except that 400 Error…

What could I do to further debug it?

Hello @Wolfgang,

Could you possibly check the response provided by the WooCommerce cart action? It should normally state what is wrong with the provided arguments.

Cheers,

Hey Louis,

yeah sorry, just wanted to add that but saw that you’re already typing… you’re just too fast :smiley:

It says “no variation found”, what I don’t understand is the following. The Price get’s calculated correctly on the frontend. Also how the variations were added seems to be fine to me…so I’m not sure if that’s maybe a bug on woocommerce itself (as i mentioned, there are really a lot of possible variations on that product) or if it’s really neccessary to add all possible type of variations to a product, but on other products it works fine too.

I assume, that cwicly is doing everything okay here!?

Cheers
Wolfgang

Hello Wolfgang,

I do know that WooCommerce is sometimes a bit difficult with variations when adding them to the cart through the API.
I doubt it’s a bug with WooCommerce to be honest.
We tested a lot of different scenarios with variations, but we might have missed something here.

I’ll take a closer look tomorrow, and might get back to you for more information about the variations themselves.

Thanks for your patience!

Cheers,

Hey Louis,

ya, well probably not :smiley:

I can describe you the scenario a bit further if that helps you? I’m not an expert with the woocommerce variations to be honest.

But we thought about it the following way:
That product has 3 types of variations:
Size (column1)
Color 1 (column 2)
Color 2 (column3)

Only the size changes the price, but also one color in Color 1 can change the price. I noticed while testing the variations, that the order is important for calculating the price correctly, so we did it the following way:

All sizes that are under 120 have the same price. And all sizes above vary in price. But…all items with the color reflective are more expensive than all the other colors.

So thats why we have placed the color “reflective” on top in the order. First the sizes with different prices and as kind of “fallback” we have that #2185 with any size in color “reflective”.

Then moving on we did the same with the sizes and with any color (catching all other colors) from #2179, #2180, #2181, #2182, #2184, #2183

As a Fallback for everything else (everything else has the same color) we have the last rule #2178.

It seems that all rules work out well except the one on #2178 (catch all rule). It looks like, that there has to be at least one selection.

But what I don’t get (logically) is the following. We have (for example) another product which varies only in size. But the price stays the same on any size. So we just applied that one “catch all” rule for it and it works as expected. So for me it looks like there is some inconsistency in the rules, but I could just get the whole topic totally wrong of course :smiley:

As always, thank you very much for your help!

Cheers
Wolfgang

Hello @Wolfgang,

Looking at this on my end, I can’t seem to reproduce the error.
If possible, could you send me a frontend link by PM or to support@cwicly.com so I can play around with the requests directly?

Thanks in advance.

Cheers,

Hey Louis,

yes, you’ll get a PM in a few seconds! Thanks a lot!

Cheers
Wolfgang

1 Like