From be9b7bd4b5648e9769c0d6bc642e8b8eb4389e4c Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 20 Apr 2016 12:35:06 +0100 Subject: [PATCH] If no variation ID is set, do a match Closes #10737 --- includes/class-wc-form-handler.php | 8 +++++++- includes/class-wc-product-variable.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-form-handler.php b/includes/class-wc-form-handler.php index aa27c274ab2..2f64549b4c7 100644 --- a/includes/class-wc-form-handler.php +++ b/includes/class-wc-form-handler.php @@ -713,7 +713,13 @@ class WC_Form_Handler { $missing_attributes = array(); $variations = array(); $attributes = $adding_to_cart->get_attributes(); - $variation = wc_get_product( $variation_id ); + + // If no variation ID is set, attempt to get a variation ID from posted attributes. + if ( empty( $variation_id ) ) { + $variation_id = $adding_to_cart->get_matching_variation( wp_unslash( $_POST ) ); + } + + $variation = wc_get_product( $variation_id ); // Verify all attributes foreach ( $attributes as $attribute ) { diff --git a/includes/class-wc-product-variable.php b/includes/class-wc-product-variable.php index b86c532106d..6ba6c6c4151 100644 --- a/includes/class-wc-product-variable.php +++ b/includes/class-wc-product-variable.php @@ -560,7 +560,7 @@ class WC_Product_Variable extends WC_Product { } /** - * Returns an array of date for a variation. Used in the add to cart form. + * Returns an array of data for a variation. Used in the add to cart form. * @since 2.4.0 * @param WC_Product $variation Variation product object or ID * @return array