Automattic\WooCommerce\Internal\DataStores\Orders

DataSynchronizer::get_ids_of_orders_pending_sync()publicWC 1.0

Get a list of ids of orders than are out of sync.

Valid values for $type are:

ID_TYPE_MISSING_IN_ORDERS_TABLE: orders that exist in posts table but not in orders table. ID_TYPE_MISSING_IN_POSTS_TABLE: orders that exist in orders table but not in posts table (the corresponding post entries are placeholders). ID_TYPE_DIFFERENT_UPDATE_DATE: orders that exist in both tables but have different last update dates.

{} Это метод класса: DataSynchronizer{}

Хуков нет.

Возвращает

Массив. An array of order ids.

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

$DataSynchronizer = new DataSynchronizer();
$DataSynchronizer->get_ids_of_orders_pending_sync( $type, $limit );
$type(int) (обязательный)
One of ID_TYPE_MISSING_IN_ORDERS_TABLE, ID_TYPE_MISSING_IN_POSTS_TABLE, ID_TYPE_DIFFERENT_UPDATE_DATE.
$limit(int) (обязательный)
Maximum number of ids to return.

Код DataSynchronizer::get_ids_of_orders_pending_sync() WC 6.6.1

public function get_ids_of_orders_pending_sync( int $type, int $limit ) {
	global $wpdb;

	if ( $limit < 1 ) {
		throw new \Exception( '$limit must be at least 1' );
	}

	$orders_table = $wpdb->prefix . 'wc_orders';

	switch ( $type ) {
		case self::ID_TYPE_MISSING_IN_ORDERS_TABLE:
			$sql = "
SELECT posts.ID FROM $wpdb->posts posts
LEFT JOIN $orders_table orders ON posts.ID = orders.id
WHERE
  posts.post_type='shop_order'
  AND posts.post_status != 'auto-draft'
  AND orders.id IS NULL";
			break;
		case self::ID_TYPE_MISSING_IN_POSTS_TABLE:
			$sql = "
SELECT posts.ID FROM $wpdb->posts posts
INNER JOIN $orders_table orders ON posts.id=orders.id
WHERE posts.post_type = '" . self::PLACEHOLDER_ORDER_POST_TYPE . "'";
			break;
		case self::ID_TYPE_DIFFERENT_UPDATE_DATE:
			$sql = "
SELECT orders.id FROM $orders_table orders
JOIN $wpdb->posts posts on posts.ID = orders.id
WHERE
  posts.post_type = 'shop_order'
  AND orders.date_updated_gmt != posts.post_modified_gmt";
			break;
		default:
			throw new \Exception( 'Invalid $type, must be one of the ID_TYPE_... constants.' );
	}

	// phpcs:ignore WordPress.DB
	return array_map( 'intval', $wpdb->get_col( $sql . " LIMIT $limit" ) );
}