Last active
December 13, 2023 13:22
-
-
Save Luc45/06f1ab20d8fb4c0ac8f3878f0138c5ad to your computer and use it in GitHub Desktop.
WooCommerce Enable COT - Q4 2023
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WooCommerce Enable COT | |
* Description: Adds the code to enable Custom Order Tables. | |
* Version: 0.0.4 | |
*/ | |
function wc_enable_cot() { | |
/** @var \Automattic\WooCommerce\Internal\Features\FeaturesController $features_controller */ | |
$features_controller = wc_get_container()->get( 'Automattic\WooCommerce\Internal\Features\FeaturesController' ); | |
// Early bail: HPOS is already enabled. | |
if ( $features_controller->feature_is_enabled( 'custom_order_tables' ) ) { | |
return; | |
} | |
/** @var \Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer $synchronizer */ | |
$synchronizer = wc_get_container()->get( 'Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer' ); | |
$pending_sync = $synchronizer->get_current_orders_pending_sync_count(); | |
if ( $pending_sync ) { | |
$synchronizer->create_database_tables(); | |
$synchronizer->process_batch( $synchronizer->get_next_batch_to_process( $pending_sync ) ); | |
} | |
$features_controller->change_feature_enable( 'custom_order_tables', true ); | |
} | |
add_action( 'init', 'wc_enable_cot', 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment