We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents bcb6b90 + 83257d9 commit bc785d8Copy full SHA for bc785d8
includes/data-stores/class-wc-product-data-store-custom-table.php
@@ -2273,4 +2273,22 @@ public function query( $query_vars ) {
2273
2274
return $products;
2275
}
2276
+
2277
+ /**
2278
+ * Returns query statement for getting current `stock_quantity` of a product.
2279
+ *
2280
+ * @internal MAX function below is used to make sure result is a scalar.
2281
+ * @param int $product_id Product ID.
2282
+ * @return string|void Query statement.
2283
+ */
2284
+ public function get_query_for_stock( $product_id ) {
2285
+ global $wpdb;
2286
+ return $wpdb->prepare(
2287
+ "
2288
+ SELECT COALESCE ( MAX( stock_quantity ), 0 ) FROM {$wpdb->prefix}wc_products
2289
+ WHERE product_id = %d
2290
+ ",
2291
+ $product_id
2292
+ );
2293
+ }
2294
0 commit comments