From eddec91b5a48f8f0b327934bc9112f01ffa150d3 Mon Sep 17 00:00:00 2001 From: Justin Shreve Date: Thu, 18 Jun 2015 20:51:17 +0000 Subject: [PATCH 1/2] If a quantity is set in the $_POST request, use that over the field default. This way, if a validation error occurs, the user's requested quantity stays the same. --- templates/single-product/add-to-cart/grouped.php | 7 ++++++- templates/single-product/add-to-cart/simple.php | 8 +++++--- templates/single-product/add-to-cart/variable.php | 4 +++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/templates/single-product/add-to-cart/grouped.php b/templates/single-product/add-to-cart/grouped.php index 08ad65a5a7e..8219a8f92cd 100644 --- a/templates/single-product/add-to-cart/grouped.php +++ b/templates/single-product/add-to-cart/grouped.php @@ -38,7 +38,12 @@ do_action( 'woocommerce_before_add_to_cart_form' ); ?> 'quantity[' . $product_id . ']', 'input_value' => '0', 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 0, $product ), 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product ) ) ); + woocommerce_quantity_input( array( + 'input_name' => 'quantity[' . $product_id . ']', + 'input_value' => ( isset( $_POST['quantity'][$product_id] ) ? $_POST['quantity'][$product_id] : 0 ), + 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 0, $product ), + 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product ) + ) ); ?> diff --git a/templates/single-product/add-to-cart/simple.php b/templates/single-product/add-to-cart/simple.php index da6e7fdcdf1..a702f15a96b 100644 --- a/templates/single-product/add-to-cart/simple.php +++ b/templates/single-product/add-to-cart/simple.php @@ -35,11 +35,13 @@ if ( ! $product->is_purchasable() ) { is_sold_individually() ) + if ( ! $product->is_sold_individually() ) { woocommerce_quantity_input( array( - 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 1, $product ), - 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product ) + 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 1, $product ), + 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product ), + 'input_value' => ( isset( $_POST['quantity'] ) ? $_POST['quantity'] : 1 ) ) ); + } ?> diff --git a/templates/single-product/add-to-cart/variable.php b/templates/single-product/add-to-cart/variable.php index fdd0ad81d14..96cd6bb99d3 100644 --- a/templates/single-product/add-to-cart/variable.php +++ b/templates/single-product/add-to-cart/variable.php @@ -76,7 +76,9 @@ global $product, $post;
- + ( isset( $_POST['quantity'] ) ? $_POST['quantity'] : 1 ) + ) ); ?>
From 5b7c51b5de79545b1b287c466c44e5b7e53829e3 Mon Sep 17 00:00:00 2001 From: Justin Shreve Date: Thu, 18 Jun 2015 23:16:00 +0000 Subject: [PATCH 2/2] Wrap the quantity from $_POST in wc_stock_amount to cast it properly --- templates/single-product/add-to-cart/grouped.php | 2 +- templates/single-product/add-to-cart/simple.php | 2 +- templates/single-product/add-to-cart/variable.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/single-product/add-to-cart/grouped.php b/templates/single-product/add-to-cart/grouped.php index 8219a8f92cd..193608a1f9e 100644 --- a/templates/single-product/add-to-cart/grouped.php +++ b/templates/single-product/add-to-cart/grouped.php @@ -40,7 +40,7 @@ do_action( 'woocommerce_before_add_to_cart_form' ); ?> $quantites_required = true; woocommerce_quantity_input( array( 'input_name' => 'quantity[' . $product_id . ']', - 'input_value' => ( isset( $_POST['quantity'][$product_id] ) ? $_POST['quantity'][$product_id] : 0 ), + 'input_value' => ( isset( $_POST['quantity'][$product_id] ) ? wc_stock_amount( $_POST['quantity'][$product_id] ) : 0 ), 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 0, $product ), 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product ) ) ); diff --git a/templates/single-product/add-to-cart/simple.php b/templates/single-product/add-to-cart/simple.php index a702f15a96b..763ff8ac141 100644 --- a/templates/single-product/add-to-cart/simple.php +++ b/templates/single-product/add-to-cart/simple.php @@ -39,7 +39,7 @@ if ( ! $product->is_purchasable() ) { woocommerce_quantity_input( array( 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 1, $product ), 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product ), - 'input_value' => ( isset( $_POST['quantity'] ) ? $_POST['quantity'] : 1 ) + 'input_value' => ( isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : 1 ) ) ); } ?> diff --git a/templates/single-product/add-to-cart/variable.php b/templates/single-product/add-to-cart/variable.php index 96cd6bb99d3..0febaa8a4fe 100644 --- a/templates/single-product/add-to-cart/variable.php +++ b/templates/single-product/add-to-cart/variable.php @@ -77,7 +77,7 @@ global $product, $post;
( isset( $_POST['quantity'] ) ? $_POST['quantity'] : 1 ) + 'input_value' => ( isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : 1 ) ) ); ?>