Finding your WooCommerce variations are being lost when you edit a product? You need to read this to find out why and what to do about it.
max_input_vars is a setting used by PHP. Its purpose is to limit the number of fields that can be sent to a website when a form is submitted. By default it is set to 1000, and that is how most people will have it set up for their websites. If means that if you submit a form with more than 1000 fields on, then any fields after the first 1000 will be discarded and the website will never see them.
Not a problem, I hear you say. Who in their right mind is going to write a form with 1000 fields that need to be filled in? Quite a few applications, it seems.
The application for which this setting is affecting some of my clients, is WooCommerce. This is a free e-commerce plugin for WordPress. When you create a product, the product can be set up as a variable product, and that variable product can have many variations to it. This is where the trouble starts.
A variable product with around 30 variations, can have well over 1000 fields in its edit form. You do not see all of those fields at once, as many are hidden behind tabs and drop-down panels. Others are hidden permanently within the form as a part of how it works. When you edit a product with 30+ variations, you are presented with the edit screen and all the product’s data. You can amend that product and save it back to the server, and everything looks fine. However, you may then find that some variations have disappeared. Worse still, you may not find the variations that have disappeared, but they will be impacting on your online shop.
WooCommerce does not warn you if it has lost variations when saving a product. It does not abort the save with an error if it finds that fields that should be on the form have not made it to the server. It should, but it doesn’t.
So this is my solution to that specific problem, i.e. not knowing that there is a problem. This is my plugin:
You can install it direct into your WordPress installatino by searching for “WP Max Submit Protect”. It’s not a very sexy name, but does what it says.
The plugin will sit in the background of all your admin pages and monitor when you you are submitting a form. That can be any form – a product, a blog post, a page – anything. It will scan the form to see how many fields are going to be submitted. It is clever enough to ignore the fields that won’t get submitted, such as checkboxes that are not checked, and it will count up all the options of fields that will be submitted as multiple fields, such as multi-select lists.
If the number of fields exceeds the number that the server will accept, then it will flash up a warning and give you chance to back out and fix the server before you try submitting the form (e.g. updating your valuable product) again.
What it does not do is fix the underlying problem. To do that , there are details available here on the WooCommerce knowledgebase, but it will keep you out of trouble, and in doing that, serves its purpose.
As well as max_input_vars, there are PHP settings and modules that do similar things and may or may not be installed on your server. Suhosin is one such module, and this plugin will be on the lookout for those settings too.
So what should you do if you run a WooCommerce shop and use variable products? Increase max_input_vars for a start. But what arbitrary value do you set it to? It does not matter – try 2000 to start with, but then do install “WP Max Submit Protect” and if you inadvertently blow the 2000 limit, you get a warning instead of silently losing data.