Automattic\WooCommerce\Blocks\Templates
SingleProductTemplate::is_password_protected_replacement_block
Whether this block should be replaced with the password form (or removed after the first replacement).
This list is not every block that can appear on a single product template. Blocks such as breadcrumbs stay visible on password-protected products.
Method of the class: SingleProductTemplate{}
No Hooks.
Returns
bool.
Usage
$result = SingleProductTemplate::is_password_protected_replacement_block( $block );
- $block(array) (required)
- Parsed block.
SingleProductTemplate::is_password_protected_replacement_block() SingleProductTemplate::is password protected replacement block code WC 11.2.1
private static function is_password_protected_replacement_block( $block ) {
$block_name = $block['blockName'] ?? '';
$single_product_template_blocks = array(
'woocommerce/product-image-gallery',
'woocommerce/product-details',
'woocommerce/add-to-cart-form',
'woocommerce/product-meta',
'woocommerce/product-rating',
'woocommerce/product-price',
'woocommerce/product-summary',
'woocommerce/related-products',
'woocommerce/add-to-cart-with-options',
'woocommerce/product-gallery',
'woocommerce/product-collection',
'core/post-title',
'core/post-excerpt',
);
if ( in_array( $block_name, $single_product_template_blocks, true ) ) {
return true;
}
if (
'core/pattern' !== $block_name ||
! isset( $block['attrs']['slug'] )
) {
return false;
}
$pattern = \WP_Block_Patterns_Registry::get_instance()->get_registered( $block['attrs']['slug'] );
if ( empty( $pattern['content'] ) ) {
return false;
}
return BlockTemplateUtils::has_block_including_patterns(
$single_product_template_blocks,
parse_blocks( $pattern['content'] )
);
}