WC_Product_Data_Store_CPT::get_query_for_stock()publicWC 1.0

Returns query statement for getting current _stock of a product.

{} Это метод класса: WC_Product_Data_Store_CPT{}

Хуков нет.

Возвращает

Строку|null. Query statement.

Использование

$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) (обязательный)
Product ID.

Код WC_Product_Data_Store_CPT::get_query_for_stock() WC 6.4.1

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