Automattic\WooCommerce\Internal\DataStores\Orders

CustomOrdersTableController::get_settings()privateWC 1.0

Get the settings for the "Custom data stores" section in the "Advanced" tab, with entries for managing the custom orders tables if appropriate.

Метод класса: CustomOrdersTableController{}

No Hooks.

Return

Array. The updated settings array.

Usage

// private - for code of main (parent) class only
$result = $this->get_settings( $settings, $section_id ): array;
$settings(array) (required)
The original settings array.
$section_id(string) (required)
The settings section to get the settings for.

Code of CustomOrdersTableController::get_settings() WC 7.1.0

private function get_settings( array $settings, string $section_id ): array {
	if ( ! $this->is_feature_visible() || $section_id !== 'custom_data_stores' ) {
		return $settings;
	}

	if ( $this->data_synchronizer->check_orders_table_exists() ) {
		$settings[] = array(
			'title' => __( 'Custom orders tables', 'woocommerce' ),
			'type'  => 'title',
			'id'    => 'cot-title',
			'desc'  => sprintf(
				/* translators: %1$s = <strong> tag, %2$s = </strong> tag. */
				__( '%1$sWARNING:%2$s This feature is currently under development and may cause database instability. For contributors only.', 'woocommerce' ),
				'<strong>',
				'</strong>'
			),
		);

		$sync_status     = $this->data_synchronizer->get_sync_status();
		$sync_is_pending = $sync_status['current_pending_count'] !== 0;

		$settings[] = array(
			'title'         => __( 'Data store for orders', 'woocommerce' ),
			'id'            => self::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION,
			'default'       => 'no',
			'type'          => 'radio',
			'options'       => array(
				'yes' => __( 'Use the WooCommerce orders tables', 'woocommerce' ),
				'no'  => __( 'Use the WordPress posts table', 'woocommerce' ),
			),
			'checkboxgroup' => 'start',
			'disabled'      => $sync_is_pending ? array( 'yes', 'no' ) : array(),
		);

		if ( $sync_is_pending ) {
			$initial_pending_count = $sync_status['initial_pending_count'];
			$current_pending_count = $sync_status['current_pending_count'];
			if ( $initial_pending_count ) {
				$text =
					sprintf(
						/* translators: %1$s=current number of orders pending sync, %2$s=initial number of orders pending sync */
						_n( 'There\'s %1$s order (out of a total of %2$s) pending sync!', 'There are %1$s orders (out of a total of %2$s) pending sync!', $current_pending_count, 'woocommerce' ),
						$current_pending_count,
						$initial_pending_count
					);
			} else {
				$text =
					/* translators: %s=initial number of orders pending sync */
					sprintf( _n( 'There\'s %s order pending sync!', 'There are %s orders pending sync!', $current_pending_count, 'woocommerce' ), $current_pending_count, 'woocommerce' );
			}

			if ( $this->batch_processing_controller->is_enqueued( get_class( $this->data_synchronizer ) ) ) {
				$text .= __( "<br/>Synchronization for these orders is currently in progress.<br/>The authoritative table can't be changed until sync completes.", 'woocommerce' );
			} else {
				$text .= __( "<br/>The authoritative table can't be changed until these orders are synchronized.", 'woocommerce' );
			}

			$settings[] = array(
				'type' => 'info',
				'id'   => 'cot-out-of-sync-warning',
				'css'  => 'color: #C00000',
				'text' => $text,
			);
		}

		$settings[] = array(
			'desc' => __( 'Keep the posts table and the orders tables synchronized', 'woocommerce' ),
			'id'   => DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION,
			'type' => 'checkbox',
		);

		if ( $sync_is_pending ) {
			if ( $this->data_synchronizer->data_sync_is_enabled() ) {
				$message    = $this->custom_orders_table_usage_is_enabled() ?
					__( 'Switch to using the posts table as the authoritative data store for orders when sync finishes', 'woocommerce' ) :
					__( 'Switch to using the orders table as the authoritative data store for orders when sync finishes', 'woocommerce' );
				$settings[] = array(
					'desc' => $message,
					'id'   => self::AUTO_FLIP_AUTHORITATIVE_TABLE_ROLES_OPTION,
					'type' => 'checkbox',
				);
			}
		}

		$settings[] = array(
			'desc' => __( 'Use database transactions for the orders data synchronization', 'woocommerce' ),
			'id'   => self::USE_DB_TRANSACTIONS_OPTION,
			'type' => 'checkbox',
		);

		$isolation_level_names = self::get_valid_transaction_isolation_levels();
		$settings[]            = array(
			'desc'    => __( 'Database transaction isolation level to use', 'woocommerce' ),
			'id'      => self::DB_TRANSACTIONS_ISOLATION_LEVEL_OPTION,
			'type'    => 'select',
			'options' => array_combine( $isolation_level_names, $isolation_level_names ),
			'default' => self::DEFAULT_DB_TRANSACTIONS_ISOLATION_LEVEL,
		);
	} else {
		$settings[] = array(
			'title' => __( 'Custom orders tables', 'woocommerce' ),
			'type'  => 'title',
			'desc'  => sprintf(
				/* translators: %1$s = <em> tag, %2$s = </em> tag. */
				__( 'Create the tables first by going to %1$sWooCommerce > Status > Tools%2$s and running %1$sCreate the custom orders tables%2$s.', 'woocommerce' ),
				'<em>',
				'</em>'
			),
		);
	}

	$settings[] = array( 'type' => 'sectionend' );

	return $settings;
}