WC_Shop_Customizer::add_product_images_section()privateWC 1.0

Product images section.

Method of the class: WC_Shop_Customizer{}

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->add_product_images_section( $wp_customize );
$wp_customize(WP_Customize_Manager) (required)
Theme Customizer object.

WC_Shop_Customizer::add_product_images_section() code WC 9.4.2

private function add_product_images_section( $wp_customize ) {
	if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) {
		$regen_description = ''; // Nothing to report; Jetpack will handle magically.
	/* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
	} elseif ( apply_filters( 'woocommerce_background_image_regeneration', true ) && ! is_multisite() ) {
		$regen_description = __( 'After publishing your changes, new image sizes will be generated automatically.', 'woocommerce' );
	/* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
	} elseif ( apply_filters( 'woocommerce_background_image_regeneration', true ) && is_multisite() ) {
		/* translators: 1: tools URL 2: regen thumbs url */
		$regen_description = sprintf( __( 'After publishing your changes, new image sizes may not be shown until you regenerate thumbnails. You can do this from the <a href="%1$s" target="_blank">tools section in WooCommerce</a> or by using a plugin such as <a href="%2$s" target="_blank">Regenerate Thumbnails</a>.', 'woocommerce' ), admin_url( 'admin.php?page=wc-status&tab=tools' ), 'https://en-gb.wordpress.org/plugins/regenerate-thumbnails/' );
	} else {
		/* translators: %s: regen thumbs url */
		$regen_description = sprintf( __( 'After publishing your changes, new image sizes may not be shown until you <a href="%s" target="_blank">Regenerate Thumbnails</a>.', 'woocommerce' ), 'https://en-gb.wordpress.org/plugins/regenerate-thumbnails/' );
	}

	$wp_customize->add_section(
		'woocommerce_product_images',
		array(
			'title'       => __( 'Product Images', 'woocommerce' ),
			'description' => $regen_description,
			'priority'    => 20,
			'panel'       => 'woocommerce',
		)
	);

	if ( ! wc_get_theme_support( 'single_image_width' ) ) {
		$wp_customize->add_setting(
			'woocommerce_single_image_width',
			array(
				'default'              => 600,
				'type'                 => 'option',
				'capability'           => 'manage_woocommerce',
				'sanitize_callback'    => 'absint',
				'sanitize_js_callback' => 'absint',
			)
		);

		$wp_customize->add_control(
			'woocommerce_single_image_width',
			array(
				'label'       => __( 'Main image width', 'woocommerce' ),
				'description' => __( 'Image size used for the main image on single product pages. These images will remain uncropped.', 'woocommerce' ),
				'section'     => 'woocommerce_product_images',
				'settings'    => 'woocommerce_single_image_width',
				'type'        => 'number',
				'input_attrs' => array(
					'min'  => 0,
					'step' => 1,
				),
			)
		);
	}

	if ( ! wc_get_theme_support( 'thumbnail_image_width' ) ) {
		$wp_customize->add_setting(
			'woocommerce_thumbnail_image_width',
			array(
				'default'              => 300,
				'type'                 => 'option',
				'capability'           => 'manage_woocommerce',
				'sanitize_callback'    => 'absint',
				'sanitize_js_callback' => 'absint',
			)
		);

		$wp_customize->add_control(
			'woocommerce_thumbnail_image_width',
			array(
				'label'       => __( 'Thumbnail width', 'woocommerce' ),
				'description' => __( 'Image size used for products in the catalog.', 'woocommerce' ),
				'section'     => 'woocommerce_product_images',
				'settings'    => 'woocommerce_thumbnail_image_width',
				'type'        => 'number',
				'input_attrs' => array(
					'min'  => 0,
					'step' => 1,
				),
			)
		);
	}

	include_once WC_ABSPATH . 'includes/customizer/class-wc-customizer-control-cropping.php';

	$wp_customize->add_setting(
		'woocommerce_thumbnail_cropping',
		array(
			'default'           => '1:1',
			'type'              => 'option',
			'capability'        => 'manage_woocommerce',
			'sanitize_callback' => 'wc_clean',
		)
	);

	$wp_customize->add_setting(
		'woocommerce_thumbnail_cropping_custom_width',
		array(
			'default'              => '4',
			'type'                 => 'option',
			'capability'           => 'manage_woocommerce',
			'sanitize_callback'    => 'absint',
			'sanitize_js_callback' => 'absint',
		)
	);

	$wp_customize->add_setting(
		'woocommerce_thumbnail_cropping_custom_height',
		array(
			'default'              => '3',
			'type'                 => 'option',
			'capability'           => 'manage_woocommerce',
			'sanitize_callback'    => 'absint',
			'sanitize_js_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		new WC_Customizer_Control_Cropping(
			$wp_customize,
			'woocommerce_thumbnail_cropping',
			array(
				'section'  => 'woocommerce_product_images',
				'settings' => array(
					'cropping'      => 'woocommerce_thumbnail_cropping',
					'custom_width'  => 'woocommerce_thumbnail_cropping_custom_width',
					'custom_height' => 'woocommerce_thumbnail_cropping_custom_height',
				),
				'label'    => __( 'Thumbnail cropping', 'woocommerce' ),
				'choices'  => array(
					'1:1'       => array(
						'label'       => __( '1:1', 'woocommerce' ),
						'description' => __( 'Images will be cropped into a square', 'woocommerce' ),
					),
					'custom'    => array(
						'label'       => __( 'Custom', 'woocommerce' ),
						'description' => __( 'Images will be cropped to a custom aspect ratio', 'woocommerce' ),
					),
					'uncropped' => array(
						'label'       => __( 'Uncropped', 'woocommerce' ),
						'description' => __( 'Images will display using the aspect ratio in which they were uploaded', 'woocommerce' ),
					),
				),
			)
		)
	);
}