Automattic\WooCommerce\Internal\DataStores\Orders
CustomOrdersTableController::get_hpos_setting_for_sync() │ private │ WC 1.0
Returns the setting for rendering sync enabling setting block in Features section of the settings page.
Метод класса: CustomOrdersTableController{}
Хуков нет.
Возвращает
Массив
. Feature setting object.
Использование
// private - только в коде основоного (родительского) класса
$result = $this->get_hpos_setting_for_sync();
Код CustomOrdersTableController::get_hpos_setting_for_sync() CustomOrdersTableController::get hpos setting for sync
WC 9.7.1
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 () {
$orders_pending_sync_count = $this->data_synchronizer->get_current_orders_pending_sync_count( true );
$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 = $orders_pending_sync_count > 0;
$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(
sprintf(
// translators: %s: number of pending orders.
_n( "There's %s order pending sync.", 'There are %s orders pending sync.', $orders_pending_sync_count, 'woocommerce' ),
number_format_i18n( $orders_pending_sync_count ),
)
. ' '
. '<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 ) {
$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(
sprintf(
// translators: %s: number of pending orders.
_n(
"You can switch order data storage <strong>only when the posts and orders tables are in sync</strong>. There's currently %s order out of sync.",
'You can switch order data storage <strong>only when the posts and orders tables are in sync</strong>. There are currently %s orders out of sync. ',
$orders_pending_sync_count,
'woocommerce'
),
number_format_i18n( $orders_pending_sync_count )
)
);
}
$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->get_current_orders_pending_sync_count( true ) > 0;
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,
);
}