WC_Admin_Setup_Wizard::display_service_item()publicWC 1.0

Устарела с версии 4.6.0. Больше не поддерживается и может быть удалена. Рекомендуется заменить эту функцию на аналог.

Display service item in list.

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

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$WC_Admin_Setup_Wizard = new WC_Admin_Setup_Wizard();
$WC_Admin_Setup_Wizard->display_service_item( $item_id, $item_info );
$item_id(int) (обязательный)
Item ID.
$item_info(массив) (обязательный)
Item info array.

Список изменений

Устарела с 4.6.0

Код WC_Admin_Setup_Wizard::display_service_item() WC 8.7.0

<?php
public function display_service_item( $item_id, $item_info ) {
	_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '4.6.0', 'Onboarding is maintained in WooCommerce Admin.' );
	$item_class = 'wc-wizard-service-item';
	if ( isset( $item_info['class'] ) ) {
		$item_class .= ' ' . $item_info['class'];
	}

	$previously_saved_settings = get_option( 'woocommerce_' . $item_id . '_settings' );

	// Show the user-saved state if it was previously saved.
	// Otherwise, rely on the item info.
	if ( is_array( $previously_saved_settings ) ) {
		$should_enable_toggle = ( isset( $previously_saved_settings['enabled'] ) && 'yes' === $previously_saved_settings['enabled'] ) ? true : ( isset( $item_info['enabled'] ) && $item_info['enabled'] );
	} else {
		$should_enable_toggle = isset( $item_info['enabled'] ) && $item_info['enabled'];
	}

	$plugins = null;
	if ( isset( $item_info['repo-slug'] ) ) {
		$plugin  = array(
			'slug' => $item_info['repo-slug'],
			'name' => $item_info['name'],
		);
		$plugins = array( $plugin );
	}

	?>
	<li class="<?php echo esc_attr( $item_class ); ?>">
		<div class="wc-wizard-service-name">
			<?php if ( ! empty( $item_info['image'] ) ) : ?>
				<img src="<?php echo esc_attr( $item_info['image'] ); ?>" alt="<?php echo esc_attr( $item_info['name'] ); ?>" />
			<?php else : ?>
				<p><?php echo esc_html( $item_info['name'] ); ?></p>
			<?php endif; ?>
		</div>
		<div class="wc-wizard-service-enable">
			<span class="wc-wizard-service-toggle <?php echo esc_attr( $should_enable_toggle ? '' : 'disabled' ); ?>" tabindex="0">
				<input
					id="wc-wizard-service-<?php echo esc_attr( $item_id ); ?>"
					type="checkbox"
					name="wc-wizard-service-<?php echo esc_attr( $item_id ); ?>-enabled"
					value="yes" <?php checked( $should_enable_toggle ); ?>
					data-plugins="<?php echo wc_esc_json( wp_json_encode( $plugins ) ); ?>"
				/>
				<label for="wc-wizard-service-<?php echo esc_attr( $item_id ); ?>">
			</span>
		</div>
		<div class="wc-wizard-service-description">
			<?php echo wp_kses_post( wpautop( $item_info['description'] ) ); ?>
			<?php if ( ! empty( $item_info['settings'] ) ) : ?>
				<div class="wc-wizard-service-settings <?php echo $should_enable_toggle ? '' : 'hide'; ?>">
					<?php foreach ( $item_info['settings'] as $setting_id => $setting ) : ?>
						<?php
						$is_checkbox = 'checkbox' === $setting['type'];

						if ( $is_checkbox ) {
							$checked = false;
							if ( isset( $previously_saved_settings[ $setting_id ] ) ) {
								$checked = 'yes' === $previously_saved_settings[ $setting_id ];
							} elseif ( false === $previously_saved_settings && isset( $setting['default'] ) ) {
								$checked = 'yes' === $setting['default'];
							}
						}
						if ( 'email' === $setting['type'] ) {
							$value = empty( $previously_saved_settings[ $setting_id ] )
								? $setting['value']
								: $previously_saved_settings[ $setting_id ];
						}
						?>
						<?php $input_id = $item_id . '_' . $setting_id; ?>
						<div class="<?php echo esc_attr( 'wc-wizard-service-setting-' . $input_id ); ?>">
							<label
								for="<?php echo esc_attr( $input_id ); ?>"
								class="<?php echo esc_attr( $input_id ); ?>"
							>
								<?php echo esc_html( $setting['label'] ); ?>
							</label>
							<input
								type="<?php echo esc_attr( $setting['type'] ); ?>"
								id="<?php echo esc_attr( $input_id ); ?>"
								class="<?php echo esc_attr( 'payment-' . $setting['type'] . '-input' ); ?>"
								name="<?php echo esc_attr( $input_id ); ?>"
								value="<?php echo esc_attr( isset( $value ) ? $value : $setting['value'] ); ?>"
								placeholder="<?php echo esc_attr( $setting['placeholder'] ); ?>"
								<?php echo ( $setting['required'] ) ? 'required' : ''; ?>
								<?php echo $is_checkbox ? checked( isset( $checked ) && $checked, true, false ) : ''; ?>
								data-plugins="<?php echo wc_esc_json( wp_json_encode( isset( $setting['plugins'] ) ? $setting['plugins'] : null ) ); ?>"
							/>
							<?php if ( ! empty( $setting['description'] ) ) : ?>
								<span class="wc-wizard-service-settings-description"><?php echo esc_html( $setting['description'] ); ?></span>
							<?php endif; ?>
						</div>
					<?php endforeach; ?>
				</div>
			<?php endif; ?>
		</div>
	</li>
	<?php
}