Automattic\WooCommerce\Internal\DataStores\Orders
CustomOrdersTableController::get_hpos_setting_for_sync
Returns the setting for rendering sync enabling setting block in Features section of the settings page.
Method of the class: CustomOrdersTableController{}
No Hooks.
Returns
Array. Feature setting object.
Usage
// private - for code of main (parent) class only $result = $this->get_hpos_setting_for_sync();
CustomOrdersTableController::get_hpos_setting_for_sync() CustomOrdersTableController::get hpos setting for sync code WC 10.3.3
private function get_hpos_setting_for_sync() {
if ( 'yes' === get_transient( 'wc_installing' ) ) {
return array();
}
$get_value = function () {
return get_option( DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION );
};
$get_sync_message = function () {
$sync_in_progress = $this->batch_processing_controller->is_enqueued( get_class( $this->data_synchronizer ) );
$sync_enabled = $this->data_synchronizer->data_sync_is_enabled();
$sync_is_pending = $this->data_synchronizer->has_orders_pending_sync( true );
$sync_message = array();
$is_dangerous = $sync_is_pending && $this->changing_data_source_with_sync_pending_is_allowed();
if ( $is_dangerous ) {
$sync_message[] = wp_kses_data(
__( "There are orders pending sync.", 'woocommerce' )
. '<strong>'
. __( 'Switching data storage while sync is incomplete is dangerous and can lead to order data corruption or loss!', 'woocommerce' )
. '</strong>'
);
}
if ( ! $sync_enabled && $this->data_synchronizer->background_sync_is_enabled() ) {
$sync_message[] = __( 'Background sync is enabled.', 'woocommerce' );
}
if ( $sync_in_progress && $sync_is_pending ) {
$orders_pending_sync_count = $this->data_synchronizer->get_current_orders_pending_sync_count( true );
$sync_message[] = sprintf(
// translators: %s: number of pending orders.
__( 'Currently syncing orders... %s pending', 'woocommerce' ),
number_format_i18n( $orders_pending_sync_count )
);
if ( ! $sync_enabled ) {
$stop_sync_url = wp_nonce_url(
add_query_arg(
array(
self::STOP_SYNC_QUERY_ARG => true,
),
wc_get_container()->get( FeaturesController::class )->get_features_page_url()
),
'hpos-stop-sync'
);
$sync_message[] = sprintf(
'<a href="%1$s" class="button button-link">%2$s</a>',
esc_url( $stop_sync_url ),
__( 'Stop sync', 'woocommerce' )
);
}
} elseif ( $sync_is_pending ) {
$sync_now_url = wp_nonce_url(
add_query_arg(
array(
self::SYNC_QUERY_ARG => true,
),
wc_get_container()->get( FeaturesController::class )->get_features_page_url()
),
'hpos-sync-now'
);
if ( ! $is_dangerous ) {
$sync_message[] = wp_kses_data(
__( "You can switch order data storage <strong>only when the posts and orders tables are in sync</strong>. There are currently orders out of sync.", 'woocommerce' ),
);
}
$sync_message[] = sprintf(
'<a href="%1$s" class="button button-link">%2$s</a>',
esc_url( $sync_now_url ),
__( 'Sync orders now', 'woocommerce' )
);
}
return implode( '<br />', $sync_message );
};
$get_description_is_error = function () {
$sync_is_pending = $this->data_synchronizer->has_orders_pending_sync();
return $sync_is_pending && $this->changing_data_source_with_sync_pending_is_allowed();
};
return array(
'id' => DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION,
'title' => '',
'type' => 'checkbox',
'desc' => __( 'Enable compatibility mode (Synchronize orders between High-performance order storage and WordPress posts storage).', 'woocommerce' ),
'value' => $get_value,
'desc_tip' => $get_sync_message,
'description_is_error' => $get_description_is_error,
'row_class' => DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION,
);
}