Skip to content

Commit

Permalink
Add hold stock minutes check to order pay shortcode also
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiulodro committed Nov 28, 2018
1 parent 2198432 commit 2517f0a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions includes/shortcodes/class-wc-shortcode-checkout.php
Expand Up @@ -84,8 +84,9 @@ private static function order_pay( $order_id ) {
// Pay for existing order.
if ( isset( $_GET['pay_for_order'], $_GET['key'] ) && $order_id ) { // WPCS: input var ok, CSRF ok.
try {
$order_key = isset( $_GET['key'] ) ? wc_clean( wp_unslash( $_GET['key'] ) ) : ''; // WPCS: input var ok, CSRF ok.
$order = wc_get_order( $order_id );
$order_key = isset( $_GET['key'] ) ? wc_clean( wp_unslash( $_GET['key'] ) ) : ''; // WPCS: input var ok, CSRF ok.
$order = wc_get_order( $order_id );
$hold_stock_minutes = (int) get_option( 'woocommerce_hold_stock_minutes', 0 );

// Order or payment link is invalid.
if ( ! $order || $order->get_id() !== $order_id || $order->get_order_key() !== $order_key ) {
Expand Down Expand Up @@ -149,7 +150,7 @@ private static function order_pay( $order_id ) {
}

// Check stock based on all items in the cart and consider any held stock within pending orders.
$held_stock = wc_get_held_stock_quantity( $product, $order->get_id() );
$held_stock = ( $hold_stock_minutes > 0 ) ? wc_get_held_stock_quantity( $product, $order->get_id() ) : 0;
$required_stock = $quantities[ $product->get_stock_managed_by_id() ];

if ( $product->get_stock_quantity() < ( $held_stock + $required_stock ) ) {
Expand Down

0 comments on commit 2517f0a

Please sign in to comment.