diff --git a/includes/data-stores/class-wc-product-data-store-custom-table.php b/includes/data-stores/class-wc-product-data-store-custom-table.php index e90bc9d..d892abb 100644 --- a/includes/data-stores/class-wc-product-data-store-custom-table.php +++ b/includes/data-stores/class-wc-product-data-store-custom-table.php @@ -2273,4 +2273,22 @@ public function query( $query_vars ) { return $products; } + + /** + * Returns query statement for getting current `stock_quantity` of a product. + * + * @internal MAX function below is used to make sure result is a scalar. + * @param int $product_id Product ID. + * @return string|void Query statement. + */ + public function get_query_for_stock( $product_id ) { + global $wpdb; + return $wpdb->prepare( + " + SELECT COALESCE ( MAX( stock_quantity ), 0 ) FROM {$wpdb->prefix}wc_products + WHERE product_id = %d + ", + $product_id + ); + } }