Automattic\WooCommerce\Internal\VariationGallery

ClassicVariationGalleryAdmin::render_variation_gallery_fieldpublicWC 1.0

Render the variation gallery field.

Method of the class: ClassicVariationGalleryAdmin{}

No Hooks.

Returns

null. Nothing (null).

Usage

$ClassicVariationGalleryAdmin = new ClassicVariationGalleryAdmin();
$ClassicVariationGalleryAdmin->render_variation_gallery_field( $loop, $variation_data, $variation ): void;
$loop(int) (required)
Variation row index.
$variation_data(array) (required)
Variation data.
$variation(WP_Post) (required)
Variation post object.

ClassicVariationGalleryAdmin::render_variation_gallery_field() code WC 10.9.1

<?php
public function render_variation_gallery_field( int $loop, array $variation_data, WP_Post $variation ): void {
	$variation_object = wc_get_product( $variation->ID );

	if ( ! $variation_object instanceof WC_Product_Variation ) {
		return;
	}

	$image_ids = $this->get_display_image_ids( $variation_object );
	$count     = count( $image_ids );
	$field_id  = 'variable_gallery_image_ids_' . $loop;
	$hero_id   = $count > 0 ? $image_ids[0] : 0;
	?>
	<div
		class="wc-variation-gallery-field<?php echo 0 === $count ? ' is-empty' : ''; ?>"
		data-variation-id="<?php echo esc_attr( (string) $variation->ID ); ?>"
	>
		<div class="wc-variation-gallery-field__header">
			<div class="wc-variation-gallery-field__title-block">
				<strong class="wc-variation-gallery-field__title">
					<?php esc_html_e( 'Variation gallery', 'woocommerce' ); ?>
				</strong>
				<span class="wc-variation-gallery-field__count" aria-live="polite">
					<?php echo esc_html( $this->get_count_text( $count ) ); ?>
				</span>
			</div>
			<button
				type="button"
				class="button-link wc-variation-gallery-manage"
				aria-label="<?php esc_attr_e( 'Manage variation gallery images', 'woocommerce' ); ?>"
			>
				<?php esc_html_e( 'Manage', 'woocommerce' ); ?>
			</button>
		</div>

		<div class="wc-variation-gallery-field__hero" data-active-index="0">
			<?php if ( $hero_id > 0 ) : ?>
				<?php $this->render_hero_image( $hero_id ); ?>
				<span class="wc-variation-gallery-field__badge" data-primary-badge aria-hidden="true">
					<span class="dashicons dashicons-star-filled"></span>
					<?php esc_html_e( 'Primary', 'woocommerce' ); ?>
				</span>
				<button type="button" class="button wc-variation-gallery-replace">
					<?php esc_html_e( 'Replace', 'woocommerce' ); ?>
				</button>
			<?php else : ?>
				<button type="button" class="wc-variation-gallery-field__empty-cta wc-variation-gallery-manage">
					<span class="dashicons dashicons-plus-alt2" aria-hidden="true"></span>
					<?php esc_html_e( 'Add variation images', 'woocommerce' ); ?>
				</button>
			<?php endif; ?>
		</div>

		<ul class="wc-variation-gallery-field__thumbs">
			<?php foreach ( $image_ids as $index => $image_id ) : ?>
				<?php $this->render_thumbnail( $image_id, 0 === $index ); ?>
			<?php endforeach; ?>
		</ul>

		<p class="wc-variation-gallery-field__hint"<?php echo 0 === $count ? ' hidden' : ''; ?>>
			<?php esc_html_e( 'First image is used as the primary. Drag to reorder.', 'woocommerce' ); ?>
		</p>

		<input
			type="hidden"
			id="<?php echo esc_attr( $field_id ); ?>"
			name="variable_gallery_image_ids[<?php echo esc_attr( (string) $loop ); ?>]"
			class="wc-variation-gallery-image-ids"
			value="<?php echo esc_attr( implode( ',', $image_ids ) ); ?>"
		/>
	</div>
	<?php
}