Automattic\WooCommerce\Admin\API
ProductsLowInStock::get_count
Get the count of low in stock products.
Метод класса: ProductsLowInStock{}
Хуков нет.
Возвращает
int.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_count( $sidewide_stock_threshold_only, $status, $low_stock_threshold );
- $sidewide_stock_threshold_only(true|false) (обязательный)
- Boolean to check if the store is using sitewide stock threshold only.
- $status(строка) (обязательный)
- Post status.
- $low_stock_threshold(int) (обязательный)
- Low stock threshold.
Код ProductsLowInStock::get_count() ProductsLowInStock::get count WC 11.3.0
protected function get_count( $sidewide_stock_threshold_only, $status, $low_stock_threshold ) {
global $wpdb;
if ( $sidewide_stock_threshold_only ) {
$count_query_string = $this->get_count_query( $sidewide_stock_threshold_only );
$count_query_results = $wpdb->get_results(
// phpcs:ignore -- not sure why phpcs complains about this line when prepare() is used here.
$wpdb->prepare( $count_query_string, $status, $low_stock_threshold ),
);
return (int) $count_query_results[0]->total;
}
// Split the query into two queries, one for products with a custom stock threshold and one for products without a custom stock threshold.
// Splitting the queries also speeds up the query.
$count_query_with_custom_stock_threshold_string = $this->get_products_with_custom_stock_threshold_count_query_str();
$count_query_without_custom_stock_threshold_string = $this->get_products_without_custom_stock_threshold_count_query_str();
$count_query_with_custom_stock_threshold_results = $wpdb->get_results(
// phpcs:ignore -- not sure why phpcs complains about this line when prepare() is used here.
$wpdb->prepare( $count_query_with_custom_stock_threshold_string, $status ),
);
$count_query_without_custom_stock_threshold_results = $wpdb->get_results(
// phpcs:ignore -- not sure why phpcs complains about this line when prepare() is used here.
$wpdb->prepare( $count_query_without_custom_stock_threshold_string, $status, $low_stock_threshold ),
);
return (int) $count_query_with_custom_stock_threshold_results[0]->total + (int) $count_query_without_custom_stock_threshold_results[0]->total;
}