Automattic\WooCommerce\Blocks\BlockTypes

Checkout::render()protectedWC 1.0

Append frontend scripts when rendering the block.

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

Хуков нет.

Возвращает

Строку. Rendered block type output.

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

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

Код Checkout::render() WC 6.8.0

protected function render( $attributes, $content ) {
	if ( $this->is_checkout_endpoint() ) {
		// Note: Currently the block only takes care of the main checkout form -- if an endpoint is set, refer to the
		// legacy shortcode instead and do not render block.
		return '[woocommerce_checkout]';
	}

	// Deregister core checkout scripts and styles.
	wp_dequeue_script( 'wc-checkout' );
	wp_dequeue_script( 'wc-password-strength-meter' );
	wp_dequeue_script( 'selectWoo' );
	wp_dequeue_style( 'select2' );

	/**
	 * We need to check if $content has any templates from prior iterations of the block, in order to update to the latest iteration.
	 * We test the iteration version by searching for new blocks brought in by it.
	 * The blocks used for testing should be always available in the block (not removable by the user).
	 * Checkout i1's content was returning an empty div, with no data-block-name attribute
	 */
	$regex_for_empty_block = '/<div class="[a-zA-Z0-9_\- ]*wp-block-woocommerce-checkout[a-zA-Z0-9_\- ]*"><\/div>/mi';
	$has_i1_template       = preg_match( $regex_for_empty_block, $content );

	if ( $has_i1_template ) {
		// This fallback needs to match the default templates defined in our Blocks.
		$inner_blocks_html = '
			<div data-block-name="woocommerce/checkout-fields-block" class="wp-block-woocommerce-checkout-fields-block">
				<div data-block-name="woocommerce/checkout-express-payment-block" class="wp-block-woocommerce-checkout-express-payment-block"></div>
				<div data-block-name="woocommerce/checkout-contact-information-block" class="wp-block-woocommerce-checkout-contact-information-block"></div>
				<div data-block-name="woocommerce/checkout-shipping-address-block" class="wp-block-woocommerce-checkout-shipping-address-block"></div>
				<div data-block-name="woocommerce/checkout-billing-address-block" class="wp-block-woocommerce-checkout-billing-address-block"></div>
				<div data-block-name="woocommerce/checkout-shipping-methods-block" class="wp-block-woocommerce-checkout-shipping-methods-block"></div>
				<div data-block-name="woocommerce/checkout-payment-block" class="wp-block-woocommerce-checkout-payment-block"></div>' .
				( isset( $attributes['showOrderNotes'] ) && false === $attributes['showOrderNotes'] ? '' : '<div data-block-name="woocommerce/checkout-order-note-block" class="wp-block-woocommerce-checkout-order-note-block"></div>' ) .
				( isset( $attributes['showPolicyLinks'] ) && false === $attributes['showPolicyLinks'] ? '' : '<div data-block-name="woocommerce/checkout-terms-block" class="wp-block-woocommerce-checkout-terms-block"></div>' ) .
				'<div data-block-name="woocommerce/checkout-actions-block" class="wp-block-woocommerce-checkout-actions-block"></div>
			</div>
			<div data-block-name="woocommerce/checkout-totals-block" class="wp-block-woocommerce-checkout-totals-block">
				<div data-block-name="woocommerce/checkout-order-summary-block" class="wp-block-woocommerce-checkout-order-summary-block"></div>
			</div>
		';

		$content = str_replace( '</div>', $inner_blocks_html . '</div>', $content );
	}

	/**
	 * Checkout i3 added inner blocks for Order summary.
	 * We need to add them to Checkout i2 templates.
	 * The order needs to match the order in which these blocks were registered.
	 */
	$order_summary_with_inner_blocks = '$0
		<div data-block-name="woocommerce/checkout-order-summary-cart-items-block" class="wp-block-woocommerce-checkout-order-summary-cart-items-block"></div>
		<div data-block-name="woocommerce/checkout-order-summary-subtotal-block" class="wp-block-woocommerce-checkout-order-summary-subtotal-block"></div>
		<div data-block-name="woocommerce/checkout-order-summary-fee-block" class="wp-block-woocommerce-checkout-order-summary-fee-block"></div>
		<div data-block-name="woocommerce/checkout-order-summary-discount-block" class="wp-block-woocommerce-checkout-order-summary-discount-block"></div>
		<div data-block-name="woocommerce/checkout-order-summary-coupon-form-block" class="wp-block-woocommerce-checkout-order-summary-coupon-form-block"></div>
		<div data-block-name="woocommerce/checkout-order-summary-shipping-block" class="wp-block-woocommerce-checkout-order-summary-shipping-block"></div>
		<div data-block-name="woocommerce/checkout-order-summary-taxes-block" class="wp-block-woocommerce-checkout-order-summary-taxes-block"></div>
	';
	// Order summary subtotal block was added in i3, so we search for it to see if we have a Checkout i2 template.
	$regex_for_order_summary_subtotal = '/<div[\n\r\s\ta-zA-Z0-9_\-=\'"]*data-block-name="woocommerce\/checkout-order-summary-subtotal-block"[\n\r\s\ta-zA-Z0-9_\-=\'"]*>/mi';
	$regex_for_order_summary          = '/<div[\n\r\s\ta-zA-Z0-9_\-=\'"]*data-block-name="woocommerce\/checkout-order-summary-block"[\n\r\s\ta-zA-Z0-9_\-=\'"]*>/mi';
	$has_i2_template                  = ! preg_match( $regex_for_order_summary_subtotal, $content );

	if ( $has_i2_template ) {
		$content = preg_replace( $regex_for_order_summary, $order_summary_with_inner_blocks, $content );
	}

	return $content;
}