Automattic\WooCommerce\Admin\API\Reports\Taxes
DataStore::lookup_is_keyed_by_order_item
Whether the lookup's primary key includes the tax order item.
The re-key in WC_Install::create_tables() can fail on a large store, and dbDelta adds the order_item_id column either way. Writing a real tax order item id into a table still keyed on (order_id, tax_rate_id) collapses the lines sharing a rate into one row that the report then matches to a single line, which reads worse than it did before the column existed.
OrderTaxLookupMigrator reads this too: a rebuild over such a table would write every row back at zero while stepping the cursor past it, so it waits instead.
Method of the class: DataStore{}
No Hooks.
Returns
bool.
Usage
$result = DataStore::lookup_is_keyed_by_order_item(): bool;
Changelog
| Since 11.2.0 | Introduced. |
DataStore::lookup_is_keyed_by_order_item() DataStore::lookup is keyed by order item code WC 11.2.2
public static function lookup_is_keyed_by_order_item(): bool {
global $wpdb;
if ( true !== self::$lookup_keyed_by_order_item ) {
$table_name = self::get_db_table_name();
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is not user input.
self::$lookup_keyed_by_order_item = (bool) $wpdb->get_var( "SHOW KEYS FROM `{$table_name}` WHERE Key_name = 'PRIMARY' AND Column_name = 'order_item_id'" );
}
return self::$lookup_keyed_by_order_item;
}