WC_Product_Data_Store_CPT::get_query_for_stock()publicWC 1.0

Returns query statement for getting current _stock of a product.

Method of the class: WC_Product_Data_Store_CPT{}

No Hooks.

Return

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() code WC 8.7.0

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
	);
}