Automattic\WooCommerce\Admin\API

ProductsLowInStock::get_low_in_stock_count()publicWC 1.0

Return # of low in stock count.

Метод класса: ProductsLowInStock{}

Хуков нет.

Возвращает

\WP_Error|\WP_HTTP_Response|\WP_REST_Response.

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

$ProductsLowInStock = new ProductsLowInStock();
$ProductsLowInStock->get_low_in_stock_count( $request );
$request(WP_REST_Request) (обязательный)
request object.

Код ProductsLowInStock::get_low_in_stock_count() WC 9.4.2

public function get_low_in_stock_count( $request ) {
	global $wpdb;
	$status              = $request->get_param( 'status' );
	$low_stock_threshold = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );

	$sidewide_stock_threshold_only = $this->is_using_sitewide_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 ),
	);

	$total_results = (int) $count_query_results[0]->total;
	$response      = rest_ensure_response( array( 'total' => $total_results ) );
	$response->header( 'X-WP-Total', $total_results );
	$response->header( 'X-WP-TotalPages', 0 );

	return $response;
}