WC_Product_Data_Store_CPT::get_query_for_stock( int $product_id )

Returns query statement for getting current _stock of a product.


Description Description


Parameters Parameters

$product_id

(Required) Product ID.


Top ↑

Return Return

(string|void) Query statement.


Top ↑

Source Source

File: includes/data-stores/class-wc-product-data-store-cpt.php

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

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.