[HPOS] Add HPOS support for the reserved stock query (#36535)
This commit is contained in:
commit
a531f83b6d
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Add HPOS support to the reserved stock query
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
namespace Automattic\WooCommerce\Checkout\Helpers;
|
||||
|
||||
use Automattic\WooCommerce\Utilities\OrderUtil;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
|
@ -202,11 +204,20 @@ final class ReserveStock {
|
|||
*/
|
||||
private function get_query_for_reserved_stock( $product_id, $exclude_order_id = 0 ) {
|
||||
global $wpdb;
|
||||
|
||||
$join = "$wpdb->posts posts ON stock_table.`order_id` = posts.ID";
|
||||
$where_status = "posts.post_status IN ( 'wc-checkout-draft', 'wc-pending' )";
|
||||
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
|
||||
$join = "{$wpdb->prefix}wc_orders orders ON stock_table.`order_id` = orders.id";
|
||||
$where_status = "orders.status IN ( 'wc-checkout-draft', 'wc-pending' )";
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$query = $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' )
|
||||
LEFT JOIN $join
|
||||
WHERE $where_status
|
||||
AND stock_table.`expires` > NOW()
|
||||
AND stock_table.`product_id` = %d
|
||||
AND stock_table.`order_id` != %d
|
||||
|
@ -214,6 +225,7 @@ final class ReserveStock {
|
|||
$product_id,
|
||||
$exclude_order_id
|
||||
);
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
|
||||
/**
|
||||
* Filter: woocommerce_query_for_reserved_stock
|
||||
|
|
Loading…
Reference in New Issue