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