Automattic\WooCommerce\Admin\API

ProductsLowInStock::get_low_in_stock_countpublicWC 1.0

Return # of low in stock count.

Method of the class: ProductsLowInStock{}

No Hooks.

Returns

\WP_Error|\WP_HTTP_Response|\WP_REST_Response.

Usage

$ProductsLowInStock = new ProductsLowInStock();
$ProductsLowInStock->get_low_in_stock_count( $request );
$request(WP_REST_Request) (required)
request object.

ProductsLowInStock::get_low_in_stock_count() code WC 10.5.0

public function get_low_in_stock_count( $request ) {
	$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( $low_stock_threshold );
	$total_results                 = $this->get_count( $sidewide_stock_threshold_only, $status, $low_stock_threshold );

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

	return $response;
}