Automattic\WooCommerce\Admin\API

ProductsLowInStock::get_low_in_stock_products()protectedWC 1.0

Get low in stock products data.

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

Хуков нет.

Возвращает

Массив.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_low_in_stock_products( $page, $per_page, $status );
$page(int)
current page.
По умолчанию: 1
$per_page(int)
items per page.
По умолчанию: 1
$status(строка)
post status.
По умолчанию: 'publish'

Код ProductsLowInStock::get_low_in_stock_products() WC 8.7.0

protected function get_low_in_stock_products( $page = 1, $per_page = 1, $status = '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();

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

	$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 = $count_query_results[0]->total;

	return array(
		'results' => $query_results,
		'total'   => (int) $total_results,
		'pages'   => (int) ceil( $total_results / (int) $per_page ),
	);
}