Automattic\WooCommerce\Database\Migrations\CustomOrderTable
CLIRunner::disable
Disables custom order tables (HPOS) and posts to authoritative if HPOS and post tables are in sync.
OPTIONS
- [--with-sync]
- Also disables sync (if it's currently enabled).
--- default: false
---
EXAMPLES
Disable HPOS. wp wc hpos disable
Method of the class: CLIRunner{}
No Hooks.
Returns
null. Nothing (null).
Usage
$CLIRunner = new CLIRunner(); $CLIRunner->disable( $args, $assoc_args );
- $args(array) (required)
- Positional arguments passed to the command.
- $assoc_args(array) (required)
- Associative arguments (options) passed to the command.
CLIRunner::disable() CLIRunner::disable code WC 11.2.2
public function disable( $args, $assoc_args ) {
$assoc_args = wp_parse_args(
$assoc_args,
array(
'with-sync' => false,
)
);
WP_CLI::log( __( 'Running pre-disable checks...', 'woocommerce' ) );
/** DataSynchronizer instance @var DataSynchronizer $data_synchronizer */
$data_synchronizer = wc_get_container()->get( DataSynchronizer::class );
$pending_orders = $data_synchronizer->get_total_pending_count();
if ( $pending_orders > 0 ) {
return WP_CLI::error(
sprintf(
// translators: %s is the command to run (wp wc cot sync).
__( '[Failed] There are orders pending sync. Please run `%s` to sync pending orders.', 'woocommerce' ),
'wp wc hpos sync',
)
);
}
/** FeaturesController instance @var FeaturesController $feature_controller */
$feature_controller = wc_get_container()->get( FeaturesController::class );
/** CustomOrdersTableController instance @var CustomOrdersTableController $cot_status */
$cot_status = wc_get_container()->get( CustomOrdersTableController::class );
if ( ! $cot_status->custom_orders_table_usage_is_enabled() ) {
WP_CLI::warning( __( 'HPOS is already disabled.', 'woocommerce' ) );
} else {
$feature_controller->change_feature_enable( 'custom_order_tables', false );
if ( $cot_status->custom_orders_table_usage_is_enabled() ) {
return WP_CLI::warning( __( 'HPOS could not be disabled.', 'woocommerce' ) );
} else {
WP_CLI::success( __( 'HPOS disabled.', 'woocommerce' ) );
}
}
if ( $assoc_args['with-sync'] ) {
$this->toggle_compat_mode( false );
}
}