WooCommerce Code Reference

CLIRunner
in package

CLI tool for migrating order data to/from custom table.

Credits https://github.com/liquidweb/woocommerce-custom-orders-table/blob/develop/includes/class-woocommerce-custom-orders-table-cli.php.

Class CLIRunner

Table of Contents

$controller  : CustomOrdersTableController
CustomOrdersTableController instance.
$post_to_cot_migrator  : PostsToOrdersMigrationController
PostsToOrdersMigrationController instance.
$synchronizer  : mixed
DataSynchronizer instance.
count_unmigrated()  : int
Count how many orders have yet to be migrated into the custom orders table.
migrate()  : mixed
Copy order data into the postmeta table.
register_commands()  : mixed
Registers commands for CLI.
sync()  : mixed
Sync order data between the custom order tables and the core WordPress post tables.
verify_cot_data()  : mixed
Verify migrated order data with original posts data.
get_verify_order_count()  : int
Helper method to get count for orders needing verification.
is_enabled()  : bool
Check if the COT feature is enabled.
log_production_warning()  : mixed
Helper method to log warning that feature is not yet production ready.
normalize_raw_meta_data()  : array<string|int, mixed>
Helper method to normalize response from meta queries into order_id > meta_key > meta_values.
verify_meta_data()  : array<string|int, mixed>
Verify meta data as part of verifying the order object.

Properties

Methods

count_unmigrated()

Count how many orders have yet to be migrated into the custom orders table.

public count_unmigrated([array<string|int, mixed> $args = array() ][, array<string|int, mixed> $assoc_args = array() ]) : int

EXAMPLES

wp wc cot count_unmigrated

Parameters
$args : array<string|int, mixed> = array()

Positional arguments passed to the command.

$assoc_args : array<string|int, mixed> = array()

Associative arguments (options) passed to the command.

Return values
intThe number of orders to be migrated.*

migrate()

Copy order data into the postmeta table.

public migrate([array<string|int, mixed> $args = array() ][, array<string|int, mixed> $assoc_args = array() ]) : mixed

Note that this could dramatically increase the size of your postmeta table, but is recommended if you wish to stop using the custom orders table plugin.

OPTIONS

[--batch-size=] : The number of orders to process in each batch. Passing a value of 0 will disable batching.

default: 500

EXAMPLES

# Copy all order data into the post meta table, 500 posts at a time.
wp wc cot backfill --batch-size=500
Parameters
$args : array<string|int, mixed> = array()

Positional arguments passed to the command.

$assoc_args : array<string|int, mixed> = array()

Associative arguments (options) passed to the command.

Return values
mixed

sync()

Sync order data between the custom order tables and the core WordPress post tables.

public sync([array<string|int, mixed> $args = array() ][, array<string|int, mixed> $assoc_args = array() ]) : mixed

OPTIONS

[--batch-size=] : The number of orders to process in each batch.

default: 500

EXAMPLES

wp wc cot sync --batch-size=500
Parameters
$args : array<string|int, mixed> = array()

Positional arguments passed to the command.

$assoc_args : array<string|int, mixed> = array()

Associative arguments (options) passed to the command.

Return values
mixed

verify_cot_data()

Verify migrated order data with original posts data.

public verify_cot_data([array<string|int, mixed> $args = array() ][, array<string|int, mixed> $assoc_args = array() ]) : mixed

OPTIONS

[--batch-size=] : The number of orders to verify in each batch.

default: 500

[--start-from=<order_id>] : Order ID to start from.

default: 0

[--end-at=<order_id>] : Order ID to end at.

default: -1

[--verbose] : Whether to output errors as they happen in batch, or output them all together at the end.

default: false

[--order-types] : Comma seperated list of order types that needs to be verified. For example, --order-types=shop_order,shop_order_refund

default: Output of function wc_get_order_types( 'cot-migration' )

[--re-migrate] : Attempt to re-migrate orders that failed verification. You should only use this option when you have never run the site with HPOS as authoritative source of order data yet, or you have manually checked the reported errors, otherwise, you risk stale data overwriting the more recent data. This option can only be enabled when --verbose flag is also set. default: false

EXAMPLES

# Verify migrated order data, 500 orders at a time.
wp wc cot verify_cot_data --batch-size=500 --start-from=0 --end-at=10000
Parameters
$args : array<string|int, mixed> = array()

Positional arguments passed to the command.

$assoc_args : array<string|int, mixed> = array()

Associative arguments (options) passed to the command.

Return values
mixed

get_verify_order_count()

Helper method to get count for orders needing verification.

private get_verify_order_count(int $order_id_start, int $order_id_end, array<string|int, mixed> $order_types[, bool $log = true ]) : int
Parameters
$order_id_start : int

Order ID to start from.

$order_id_end : int

Order ID to end at.

$order_types : array<string|int, mixed>

List of order types to verify.

$log : bool = true

Whether to also log an error message.

Return values
intOrder count.

is_enabled()

Check if the COT feature is enabled.

private is_enabled([bool $log = true ]) : bool
Parameters
$log : bool = true

Optionally log a error message.

Return values
boolWhether the COT feature is enabled.

normalize_raw_meta_data()

Helper method to normalize response from meta queries into order_id > meta_key > meta_values.

private normalize_raw_meta_data(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>

Data fetched from meta queries.

Return values
array<string|int, mixed>Normalized data.

verify_meta_data()

Verify meta data as part of verifying the order object.

private verify_meta_data(array<string|int, mixed> $order_ids, array<string|int, mixed> $failed_ids) : array<string|int, mixed>
Parameters
$order_ids : array<string|int, mixed>

Order IDs.

$failed_ids : array<string|int, mixed>

Array for storing failed IDs.

Return values
array<string|int, mixed>Failed IDs with meta details.