__( 'Store page', 'ai-eshop-optimizer' ), 'description' => __( 'One shop from top to bottom: its name and photo with the hours, its people, the walk through the shop with its plan, what can be booked and its events, the way here, one review and the booking form.', 'ai-eshop-optimizer' ), 'content' => self::wrap( $composition ), 'post_types' => array( AIEO_Store_CPT::POST_TYPE ), ) ); register_block_template( self::ARCHIVE, array( 'title' => __( 'Store list', 'ai-eshop-optimizer' ), 'description' => __( 'Every shop as a card: whether it is open now, its address and phone, hours, what is in the shop, how to get there and its Google reviews.', 'ai-eshop-optimizer' ), 'content' => self::wrap( self::archive_body() ), ) ); self::register_after(); add_filter( 'pre_render_block', array( __CLASS__, 'crumbs_fallback' ), 10, 2 ); add_filter( 'woocommerce_get_breadcrumb', array( __CLASS__, 'crumb_archive_name' ) ); } public static function crumb_archive_name( $crumbs ) { if ( ! is_array( $crumbs ) || ! is_singular( AIEO_Store_CPT::POST_TYPE ) ) { return $crumbs; } $type = get_post_type_object( AIEO_Store_CPT::POST_TYPE ); $link = (string) get_post_type_archive_link( AIEO_Store_CPT::POST_TYPE ); if ( ! $type || '' === $link ) { return $crumbs; } foreach ( $crumbs as $i => $crumb ) { if ( is_array( $crumb ) && isset( $crumb[1] ) && untrailingslashit( (string) $crumb[1] ) === untrailingslashit( $link ) ) { $crumbs[ $i ][0] = (string) $type->labels->name; } } return $crumbs; } public static function crumbs_fallback( $pre, $parsed ) { if ( null !== $pre || ! is_array( $parsed ) || 'core/pattern' !== ( $parsed['blockName'] ?? '' ) || self::CRUMBS !== ( $parsed['attrs']['slug'] ?? '' ) || WP_Block_Patterns_Registry::get_instance()->is_registered( self::CRUMBS ) ) { return $pre; } $inner = WP_Block_Type_Registry::get_instance()->is_registered( 'woocommerce/breadcrumbs' ) ? '' : ''; $top = 'var(--wp--custom--rooster--crumbs--offset, var(--wp--preset--spacing--4, 1rem))'; return do_blocks( '' . '
' . $inner . '
' ); } private static function register_after() { if ( ! function_exists( 'register_block_pattern' ) || WP_Block_Patterns_Registry::get_instance()->is_registered( self::AFTER ) ) { return; } $markup = (string) apply_filters( 'aieo_stores_page_after', '' ); register_block_pattern( self::AFTER, array( 'title' => __( 'Under the Stores page\'s shops', 'ai-eshop-optimizer' ), 'content' => $markup, 'inserter' => false, ) ); } public static function composition() { if ( ! defined( 'AIEO_DIR' ) ) { return ''; } $file = AIEO_DIR . 'includes/dmm/blocks/patterns/store-page.php'; if ( ! is_readable( $file ) ) { return ''; } $args = include $file; return ( is_array( $args ) && ! empty( $args['content'] ) ) ? (string) $args['content'] : ''; } private static function wrap( $body ) { return '' . "\n\n" . $body . "\n\n" . ''; } private static function archive_body() { $title = esc_html( (string) apply_filters( 'aieo_stores_page_title', __( 'Our stores', 'ai-eshop-optimizer' ) ) ); $lede = esc_html( (string) apply_filters( 'aieo_stores_page_lead', __( 'Find your nearest shop: whether it is open now, its address and phone, opening hours, directions and its Google reviews.', 'ai-eshop-optimizer' ) ) ); return '

' . $title . '

' . $lede . '

'; } } }