Automattic\WooCommerce\Internal\ProductCustoms

ClassicEditorFields::render_fields │ public │ WC 11.3.0

Outputs the customs fields for a product, or for a variation when a parent and loop index are given.

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

Хуков нет.

Возвращает

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

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

$ClassicEditorFields = new ClassicEditorFields();
$ClassicEditorFields->render_fields( $product, ?WC_Product $parent_product, ?int $loop ): void;
$product(WC_Product) (обязательный)
Product being edited.
?WC_Product $parent_product
.
По умолчанию: null
?int $loop
.
По умолчанию: null

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

С версии 11.3.0 Введена.

Код ClassicEditorFields::render_fields() WC 11.3.0

<?php
public function render_fields( WC_Product $product, ?WC_Product $parent_product = null, ?int $loop = null ): void {
	$countries      = WC()->countries->get_countries();
	$parent_code    = $parent_product ? $parent_product->get_customs_commodity_code( 'edit' ) : null;
	$parent_country = $parent_product ? $parent_product->get_customs_country_of_origin( 'edit' ) : null;
	$parent_desc    = $parent_product ? $parent_product->get_customs_description( 'edit' ) : null;
	?>
	<div class="wc-product-customs <?php echo null !== $loop ? 'hide_if_variation_virtual' : ''; ?>">
		<h4><?php esc_html_e( 'Customs', 'woocommerce' ); ?></h4>
		<?php
		woocommerce_wp_text_input(
			$this->get_field_args( 'customs_commodity_code', $loop ) + array(
				'value'       => $product->get_customs_commodity_code( 'edit' ) ?? '',
				'label'       => __( 'Commodity code', 'woocommerce' ),
				'description' => $this->get_help_text( __( 'The HS (Harmonized System) code used to classify this product for customs. Enter 6–14 digits; spaces and punctuation are removed.', 'woocommerce' ), $parent_code ),
				'placeholder' => $parent_code ?? '',
			),
			$product
		);

		woocommerce_wp_select(
			$this->get_field_args( 'customs_country_of_origin', $loop ) + array(
				'value'       => $product->get_customs_country_of_origin( 'edit' ) ?? '',
				'label'       => __( 'Country of origin', 'woocommerce' ),
				'description' => $this->get_help_text( __( 'The country where this product was manufactured or produced.', 'woocommerce' ), null === $parent_country ? null : ( $countries[ $parent_country ] ?? $parent_country ) ),
				'options'     => array( '' => null !== $parent_country ? __( 'Same as parent', 'woocommerce' ) : __( 'Select a country', 'woocommerce' ) ) + $countries,
			),
			$product
		);

		woocommerce_wp_text_input(
			$this->get_field_args( 'customs_description', $loop ) + array(
				'value'       => $product->get_customs_description( 'edit' ) ?? '',
				'label'       => __( 'Customs description', 'woocommerce' ),
				'description' => $this->get_help_text( __( 'A plain-text description for customs forms, up to 35 characters. Emoji and special symbols are not allowed.', 'woocommerce' ), $parent_desc ),
				'placeholder' => $parent_desc ?? '',
			),
			$product
		);
		?>
	</div>
	<?php
}