Validate all possible values for variation add to cart

Closes #15481
This commit is contained in:
Mike Jolley 2017-06-07 11:13:28 +01:00
parent 4138b2b982
commit bea7492e23
1 changed files with 4 additions and 1 deletions

View File

@ -826,7 +826,10 @@ class WC_Form_Handler {
$valid_value = isset( $variation_data[ $taxonomy ] ) ? $variation_data[ $taxonomy ] : '';
// Allow if valid or show error.
if ( '' === $valid_value || $valid_value === $value ) {
if ( $valid_value === $value ) {
$variations[ $taxonomy ] = $value;
// If valid values are empty, this is an 'any' variation so get all possible values.
} elseif ( '' === $valid_value && in_array( $value, $attribute->get_slugs() ) ) {
$variations[ $taxonomy ] = $value;
} else {
throw new Exception( sprintf( __( 'Invalid value posted for %s', 'woocommerce' ), wc_attribute_label( $attribute['name'] ) ) );