Automattic\WooCommerce\Admin\API
ProductsLowInStock::get_low_in_stock_products
Get low in stock products data.
Method of the class: ProductsLowInStock{}
No Hooks.
Returns
Array.
Usage
// protected - for code of main (parent) or child class $result = $this->get_low_in_stock_products( $page, $per_page, $status );
- $page(int)
- current page.
Default:1 - $per_page(int)
- items per page.
Default:1 - $status(string)
- post status.
Default:ProductStatus::PUBLISH
ProductsLowInStock::get_low_in_stock_products() ProductsLowInStock::get low in stock products code WC 10.6.2
protected function get_low_in_stock_products( $page = 1, $per_page = 1, $status = ProductStatus::PUBLISH ) {
global $wpdb;
$offset = ( $page - 1 ) * $per_page;
$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 );
$query_string = $this->get_query( $sidewide_stock_threshold_only );
$query_results = $wpdb->get_results(
// phpcs:ignore -- not sure why phpcs complains about this line when prepare() is used here.
$wpdb->prepare( $query_string, $status, $low_stock_threshold, $offset, $per_page ),
OBJECT_K
);
$total_results = $this->get_count( $sidewide_stock_threshold_only, $status, $low_stock_threshold );
return array(
'results' => $query_results,
'total' => (int) $total_results,
'pages' => (int) ceil( $total_results / (int) $per_page ),
);
}