Automattic\WooCommerce\Blocks\BlockTypes

MiniCart::get_markup()protectedWC 1.0

Render the markup for the Mini Cart block.

{} Это метод класса: MiniCart{}

Хуков нет.

Возвращает

Строку. The HTML markup.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_markup( $attributes );
$attributes(массив) (обязательный)
Block attributes.

Код MiniCart::get_markup() WC 6.9.4

protected function get_markup( $attributes ) {
	if ( is_admin() || WC()->is_rest_api_request() ) {
		// In the editor we will display the placeholder, so no need to load
		// real cart data and to print the markup.
		return '';
	}

	$cart_controller     = $this->get_cart_controller();
	$cart                = $cart_controller->get_cart_instance();
	$cart_contents_count = $cart->get_cart_contents_count();
	$cart_contents       = $cart->get_cart();
	$cart_contents_total = $cart->get_subtotal();

	if ( $cart->display_prices_including_tax() ) {
		$cart_contents_total += $cart->get_subtotal_tax();
	}

	$classes_styles  = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array( 'text_color', 'background_color', 'font_size', 'font_family' ) );
	$wrapper_classes = sprintf( 'wc-block-mini-cart wp-block-woocommerce-mini-cart %s', $classes_styles['classes'] );
	if ( ! empty( $attributes['className'] ) ) {
		$wrapper_classes .= ' ' . $attributes['className'];
	}
	$wrapper_styles = $classes_styles['styles'];

	$aria_label = sprintf(
	/* translators: %1$d is the number of products in the cart. %2$s is the cart total */
		_n(
			'%1$d item in cart, total price of %2$s',
			'%1$d items in cart, total price of %2$s',
			$cart_contents_count,
			'woocommerce'
		),
		$cart_contents_count,
		wp_strip_all_tags( wc_price( $cart_contents_total ) )
	);
	$icon        = '<svg class="wc-block-mini-cart__icon" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
		<path fill-rule="evenodd" clip-rule="evenodd" d="M7.84614 18.2769C7.89712 18.2769 7.93845 18.2356 7.93845 18.1846C7.93845 18.1336 7.89712 18.0923 7.84614 18.0923C7.79516 18.0923 7.75384 18.1336 7.75384 18.1846C7.75384 18.2356 7.79516 18.2769 7.84614 18.2769ZM6.03076 18.1846C6.03076 17.182 6.84353 16.3692 7.84614 16.3692C8.84875 16.3692 9.66152 17.182 9.66152 18.1846C9.66152 19.1872 8.84875 20 7.84614 20C6.84353 20 6.03076 19.1872 6.03076 18.1846Z" fill="currentColor"/>
		<path fill-rule="evenodd" clip-rule="evenodd" d="M17.3231 18.2769C17.3741 18.2769 17.4154 18.2356 17.4154 18.1846C17.4154 18.1336 17.3741 18.0923 17.3231 18.0923C17.2721 18.0923 17.2308 18.1336 17.2308 18.1846C17.2308 18.2356 17.2721 18.2769 17.3231 18.2769ZM15.5077 18.1846C15.5077 17.182 16.3205 16.3692 17.3231 16.3692C18.3257 16.3692 19.1385 17.182 19.1385 18.1846C19.1385 19.1872 18.3257 20 17.3231 20C16.3205 20 15.5077 19.1872 15.5077 18.1846Z" fill="currentColor"/>
		<path fill-rule="evenodd" clip-rule="evenodd" d="M20.0631 9.53835L19.4662 12.6685L19.4648 12.6757L19.4648 12.6757C19.3424 13.2919 19.0072 13.8454 18.5178 14.2394C18.031 14.6312 17.4226 14.8404 16.798 14.8308H8.44017C7.81556 14.8404 7.20714 14.6312 6.72038 14.2394C6.2312 13.8456 5.89605 13.2924 5.77352 12.6765L5.77335 12.6757L4.33477 5.48814C4.3286 5.46282 4.32345 5.43711 4.31934 5.41104L3.61815 1.90768H0.953842C0.42705 1.90768 0 1.48063 0 0.953842C0 0.42705 0.42705 0 0.953842 0H4.4C4.85462 0 5.24607 0.320858 5.33529 0.766644L6.04403 4.30769H12.785C13.0114 4.99157 13.3319 5.63258 13.7312 6.21538H6.42585L7.64421 12.3026L7.64449 12.304C7.67966 12.4811 7.77599 12.6402 7.91662 12.7534C8.05725 12.8666 8.23322 12.9267 8.41372 12.9233L8.432 12.9231H16.8062L16.8244 12.9233C17.0049 12.9267 17.1809 12.8666 17.3215 12.7534C17.4614 12.6408 17.5575 12.4828 17.5931 12.3068L17.5937 12.304L18.1649 9.30867C18.762 9.45873 19.387 9.53842 20.0307 9.53842C20.0415 9.53842 20.0523 9.5384 20.0631 9.53835Z" fill="currentColor"/>
	</svg>';
	$button_html = $this->get_cart_price_markup( $attributes ) . '
	<span class="wc-block-mini-cart__quantity-badge">
		' . $icon . '
		<span class="wc-block-mini-cart__badge">' . $cart_contents_count . '</span>
	</span>';

	if ( is_cart() || is_checkout() ) {
		// It is not necessary to load the Mini Cart Block on Cart and Checkout page.
			return '<div class="' . $wrapper_classes . '" style="visibility:hidden" aria-hidden="true">
			<button class="wc-block-mini-cart__button" aria-label="' . esc_attr( $aria_label ) . '" disabled>' . $button_html . '</button>
		</div>';
	}

	$template_part_contents = '';

	// Determine if we need to load the template part from the theme, or WooCommerce in that order.
	$theme_has_mini_cart   = BlockTemplateUtils::theme_has_template_part( 'mini-cart' );
	$template_slug_to_load = $theme_has_mini_cart ? get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG;
	$template_part         = BlockTemplateUtils::get_block_template( $template_slug_to_load . '//mini-cart', 'wp_template_part' );

	if ( $template_part && ! empty( $template_part->content ) ) {
		$template_part_contents = do_blocks( $template_part->content );
	}

	if ( '' === $template_part_contents ) {
		$template_part_contents = do_blocks(
			// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
			file_get_contents( Package::get_path() . 'templates/' . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATE_PARTS'] . '/mini-cart.html' )
		);
	}

	return '<div class="' . $wrapper_classes . '" style="' . $wrapper_styles . '">
		<button class="wc-block-mini-cart__button" aria-label="' . esc_attr( $aria_label ) . '">' . $button_html . '</button>
		<div class="wc-block-mini-cart__drawer is-loading is-mobile wc-block-components-drawer__screen-overlay wc-block-components-drawer__screen-overlay--is-hidden" aria-hidden="true">
			<div class="components-modal__frame wc-block-components-drawer">
				<div class="components-modal__content">
					<div class="components-modal__header">
						<div class="components-modal__header-heading-container"></div>
					</div>
					<div class="wc-block-mini-cart__template-part">'
					. wp_kses_post( $template_part_contents ) .
					'</div>
				</div>
			</div>
		</div>
	</div>';
}