Automattic\WooCommerce\Internal\Admin\Schedulers

OrdersScheduler::get_items_from_posts_table()private staticWC 1.0

Helper method to ger order/refund IDS and total count that needs to be synced.

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

Хуков нет.

Возвращает

Объект. Total counts.

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

$result = OrdersScheduler::get_items_from_posts_table( $limit, $page, $days, $skip_existing );
$limit(int) (обязательный)
Number of records to retrieve.
$page(int) (обязательный)
Page number.
$days(int|true|false) (обязательный)
Number of days prior to current date to limit search results.
$skip_existing(true|false) (обязательный)
Skip already imported orders.

Код OrdersScheduler::get_items_from_posts_table() WC 9.3.3

private static function get_items_from_posts_table( $limit, $page, $days, $skip_existing ) {
	global $wpdb;
	$where_clause = '';
	$offset       = $page > 1 ? ( $page - 1 ) * $limit : 0;

	if ( is_int( $days ) ) {
		$days_ago      = gmdate( 'Y-m-d 00:00:00', time() - ( DAY_IN_SECONDS * $days ) );
		$where_clause .= " AND post_date_gmt >= '{$days_ago}'";
	}

	if ( $skip_existing ) {
		$where_clause .= " AND NOT EXISTS (
			SELECT 1 FROM {$wpdb->prefix}wc_order_stats
			WHERE {$wpdb->prefix}wc_order_stats.order_id = {$wpdb->posts}.ID
		)";
	}

	$count = $wpdb->get_var(
		"SELECT COUNT(*) FROM {$wpdb->posts}
		WHERE post_type IN ( 'shop_order', 'shop_order_refund' )
		AND post_status NOT IN ( 'wc-auto-draft', 'auto-draft', 'trash' )
		{$where_clause}"
	); // phpcs:ignore unprepared SQL ok.

	$order_ids = absint( $count ) > 0 ? $wpdb->get_col(
		$wpdb->prepare(
			"SELECT ID FROM {$wpdb->posts}
			WHERE post_type IN ( 'shop_order', 'shop_order_refund' )
			AND post_status NOT IN ( 'wc-auto-draft', 'auto-draft', 'trash' )
			{$where_clause}
			ORDER BY post_date_gmt ASC
			LIMIT %d
			OFFSET %d",
			$limit,
			$offset
		)
	) : array(); // phpcs:ignore unprepared SQL ok.

	return (object) array(
		'total' => absint( $count ),
		'ids'   => $order_ids,
	);
}