Woocommerce Varations Not Saving: The Case of the Missing $_Post Variables

Published by John on May 31, 2015 Under PHP, Wordpress

One of my clients using Woocommerce, along with the Woocommerce Color or Image Variation Select plugin, was running into an issue where with some products, the variation images would not save. Instead, they would just show the default color or in some cases, it was not even possible to change any of the settings in the Coloured Variables tab.

The Woocommerce Color or Image Variation Select plugin is an add-on to Woocommerce that lets you add color swatches to a product variation. It is a third-party plugin, Woocommerce has their own version of this as well.

The problem seemed to start with products that had over 20-30 variations, but it sometimes happened rather sporadically and with products that had only a few Color Swatch Variations.

After some debugging, updating, and a bit of head scratching, I determined that on the problem products, the plugin’s _coloredvariables option was empty and the $_POST[‘coloredvariables’] variable was not being set, despite being part of the product’s edit

.

The Problem

The problem was that there were actually too many PHP $_POST variables and so the extra ones were being ignored.

PHP, as of version 5.3.9, has a variable called max_input_vars. This variable limits the number of input variables($_POST, $_GET, and $_COOKIE) that can be submitted at one time.

The default value is 1000 and if there are more than 1000, the additional variables get truncated. The purpose of having a limit is to reduce the impact a denial of service attack might have by reducing the risk of collisions.

In this case due to the large number of variations and the way the Woocommerce Color or Image Variation Select saved(each single variation adds a number of post variables,) the limit was being reached and additional variables ignored.

As a result, the variations would sometimes not save at all or other times, the last 5-10 variations would be lost during the save.

The Fix

The fix was to increase PHP’s max_input_var variable to allow for more post variables. You could do this several ways, including adding it to server’s .htaccess file, which is what is shown below. This client’s server was using Red Hat Enterprise Linux(RHEL), with PHP 5.3.15 with Suhosin-Patch, hence the suhosin. additions below.

.htaccess :

php_value max_input_vars 3000
php_value suhosin.get.max_vars 3000
php_value suhosin.post.max_vars 3000
php_value suhosin.request.max_vars 3000

While I chose to add these to the .htaccess file, you could also do it in your php.ini file or httpd.conf.


No Comments |

Add a Comment