Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

ReserveStock::get_query_for_reserved_stock( int $product_id, integer $exclude_order_id )

Returns query statement for getting reserved stock of a product.


Description Description


Parameters Parameters

$product_id

(Required) Product ID.

$exclude_order_id

(Optional) order to exclude from the results.


Top ↑

Return Return

(string|void) Query statement.


Top ↑

Source Source

File: src/Checkout/Helpers/ReserveStock.php

	private function get_query_for_reserved_stock( $product_id, $exclude_order_id = 0 ) {
		global $wpdb;
		return $wpdb->prepare(
			"
			SELECT COALESCE( SUM( stock_table.`stock_quantity` ), 0 ) FROM $wpdb->wc_reserved_stock stock_table
			LEFT JOIN $wpdb->posts posts ON stock_table.`order_id` = posts.ID
			WHERE posts.post_status IN ( 'wc-checkout-draft', 'wc-pending' )
			AND stock_table.`expires` > NOW()
			AND stock_table.`product_id` = %d
			AND stock_table.`order_id` != %d
			",
			$product_id,
			$exclude_order_id
		);
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.