Skip to content

Commit

Permalink
Merge pull request woocommerce#15495 from woocommerce/fix/15481
Browse files Browse the repository at this point in the history
Validate all possible values for variation add to cart
  • Loading branch information
mikejolley authored Jun 7, 2017
2 parents 0d7614d + bea7492 commit 25de18c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion includes/class-wc-form-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,10 @@ private static function add_to_cart_handler_variable( $product_id ) {
$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'] ) ) );
Expand Down

0 comments on commit 25de18c

Please sign in to comment.