Automattic\WooCommerce\Internal\Admin
OrderTaxLookupMigrator::get_total_pending_count
Get the number of orders left to go through that still hold rows in the shape that predates the tax order item column, up to PENDING_COUNT_LIMIT.
Counts from the cursor, the same place get_next_batch_to_process() reads from, so the number the tool shows is the number the rebuild will actually get through. Counting the whole table instead would leave the tool offering a run over orders every pass steps past.
Method of the class: OrderTaxLookupMigrator{}
No Hooks.
Returns
int. Number of orders pending processing, at most PENDING_COUNT_LIMIT.
Usage
$OrderTaxLookupMigrator = new OrderTaxLookupMigrator(); $OrderTaxLookupMigrator->get_total_pending_count(): int;
OrderTaxLookupMigrator::get_total_pending_count() OrderTaxLookupMigrator::get total pending count code WC 11.2.1
public function get_total_pending_count(): int {
global $wpdb;
// While the lookup is not keyed by tax order item there is nothing the rebuild can change,
// so no order counts as pending. See get_next_batch_to_process().
if ( ! TaxesDataStore::lookup_is_keyed_by_order_item() ) {
return 0;
}
$table_name = TaxesDataStore::get_db_table_name();
return (int) $wpdb->get_var(
$wpdb->prepare(
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is not user input.
"SELECT COUNT(*) FROM ( SELECT DISTINCT order_id FROM {$table_name} WHERE order_id > %d AND order_item_id = 0 LIMIT %d ) AS pending",
$this->get_cursor(),
self::PENDING_COUNT_LIMIT
)
);
}