Automattic\WooCommerce\Blocks\BlockTypes\OrderConfirmation

CreateAccount::initialize_hooks()protectedWC 1.0

Initialize hooks.

Method of the class: CreateAccount{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->initialize_hooks();

Notes

CreateAccount::initialize_hooks() code WC 9.6.1

protected function initialize_hooks() {
	// This does not use the Block Hooks Trait used in mini cart. The implementation is simpler because we support
	// versions higher than WP 6.5 when hooks were introduced. They should be consolodated in the future.
	add_filter(
		'hooked_block_types',
		function ( $hooked_block_types, $relative_position, $anchor_block_type, $context ) {
			if ( 'after' !== $relative_position || 'woocommerce/order-confirmation-summary' !== $anchor_block_type || ! $context instanceof \WP_Block_Template ) {
				return $hooked_block_types;
			}

			if ( ! str_contains( $context->content, '<!-- wp:' . $this->get_full_block_name() ) ) {
				$hooked_block_types[] = $this->get_full_block_name();
			}

			return $hooked_block_types;
		},
		10,
		4
	);
	add_filter(
		'hooked_block_woocommerce/order-confirmation-create-account',
		function ( $parsed_hooked_block, $hooked_block_type, $relative_position ) {
			if ( 'after' !== $relative_position || is_null( $parsed_hooked_block ) ) {
				return $parsed_hooked_block;
			}

			/* translators: %s: Site title */
			$site_title_heading                  = sprintf( __( 'Create an account with %s', 'woocommerce' ), wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) );
			$parsed_hooked_block['innerContent'] = array(
				'<div class="wp-block-woocommerce-order-confirmation-create-account alignwide">
				<!-- wp:heading {"level":3} -->
                    <h3 class="wp-block-heading">' . esc_html( $site_title_heading ) . '</h3>
				<!-- /wp:heading -->
				<!-- wp:list {"className":"is-style-checkmark-list"} -->
				<ul class="wp-block-list is-style-checkmark-list"><!-- wp:list-item -->
                    <li>' . esc_html__( 'Faster future purchases', 'woocommerce' ) . '</li>
                    <!-- /wp:list-item -->
                    <!-- wp:list-item -->
                    <li>' . esc_html__( 'Securely save payment info', 'woocommerce' ) . '</li>
                    <!-- /wp:list-item -->
                    <!-- wp:list-item -->
                    <li>' . esc_html__( 'Track orders &amp; view shopping history', 'woocommerce' ) . '</li>
                    <!-- /wp:list-item --></ul>
                    <!-- /wp:list -->
                    </div>',
			);

				return $parsed_hooked_block;
		},
		10,
		4
	);
}