Automattic\WooCommerce\Internal\DataStores\Orders
DataSynchronizer::get_current_orders_pending_sync_count()
Calculate how many orders need to be synchronized currently.
If an option whose name is given by self::FAKE_ORDERS_PENDING_SYNC_COUNT_OPTION exists, then the value of that option is returned. This is temporary, to ease testing the feature while it is in development.
Otherwise a database query is performed to get how many orders match one of the following:
- Existing in the authoritative table but not in the backup table.
- Existing in both tables, but they have a different update date.
{} It's a method of the class: DataSynchronizer{}
No Hooks.
Return
null
. Nothing.
Usage
$DataSynchronizer = new DataSynchronizer(); $DataSynchronizer->get_current_orders_pending_sync_count(): int;
Code of DataSynchronizer::get_current_orders_pending_sync_count() DataSynchronizer::get current orders pending sync count WC 6.6.1
public function get_current_orders_pending_sync_count(): int { global $wpdb; // TODO: Remove the usage of the fake pending orders count once development of the feature is complete. $count = get_option( self::FAKE_ORDERS_PENDING_SYNC_COUNT_OPTION ); if ( false !== $count ) { return (int) $count; } $orders_table = $wpdb->prefix . 'wc_orders'; if ( $this->custom_orders_table_is_authoritative() ) { $missing_orders_count_sql = " SELECT COUNT(1) FROM $wpdb->posts posts INNER JOIN $orders_table orders ON posts.id=orders.id WHERE posts.post_type = '" . self::PLACEHOLDER_ORDER_POST_TYPE . "'"; } else { $missing_orders_count_sql = " SELECT COUNT(1) 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"; } $sql = " SELECT( ($missing_orders_count_sql) + (SELECT COUNT(1) FROM ( 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 ) x) ) count"; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared return (int) $wpdb->get_var( $sql ); }