WC_Product_Data_Store_CPT::get_query_for_stock
Returns query statement for getting current _stock of a product.
Method of the class: WC_Product_Data_Store_CPT{}
No Hooks.
Returns
String|null. Query statement.
Usage
$WC_Product_Data_Store_CPT = new WC_Product_Data_Store_CPT(); $WC_Product_Data_Store_CPT->get_query_for_stock( $product_id );
- $product_id(int) (required)
- Product ID.
WC_Product_Data_Store_CPT::get_query_for_stock() WC Product Data Store CPT::get query for stock code WC 10.3.5
public function get_query_for_stock( $product_id ) {
global $wpdb;
return $wpdb->prepare(
"
SELECT COALESCE( MAX( meta_value ), 0 ) FROM $wpdb->postmeta as meta_table
WHERE meta_table.meta_key = '_stock'
AND meta_table.post_id = %d
",
$product_id
);
}