new GroupedProductAddToCartWithOptionsTemplate(); } } } } else { $template_parts = array(); } // Init all templates. foreach ( $templates as $template ) { $template->init(); // Taxonomy templates are registered automatically by WordPress and // are made available through the Add Template menu. if ( ! $template->is_taxonomy_template ) { $directory = BlockTemplateUtils::get_templates_directory( 'wp_template' ); $template_file_path = $directory . '/' . $template::SLUG . '.html'; register_block_template( 'woocommerce//' . $template::SLUG, array( 'title' => $template->get_template_title(), 'description' => $template->get_template_description(), // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents 'content' => file_get_contents( $template_file_path ), ) ); } } foreach ( $template_parts as $template_part ) { $template_part->init(); } $this->templates = array_merge( $templates, $template_parts ); } /** * Add Add to Cart + Options to the default template part areas. * * @param array $default_area_definitions An array of supported area objects. * @return array The supported template part areas including the Add to Cart + Options one. */ public function register_add_to_cart_with_options_template_part_area( $default_area_definitions ) { $add_to_cart_with_options_template_part_area = array( 'area' => 'add-to-cart-with-options', 'label' => __( 'Add to Cart + Options', 'woocommerce' ), 'description' => __( 'The Add to Cart + Options templates allow defining a different layout for each product type.', 'woocommerce' ), 'icon' => 'add-to-cart-with-options', 'area_tag' => 'add-to-cart-with-options', ); return array_merge( $default_area_definitions, array( $add_to_cart_with_options_template_part_area ) ); } /** * Returns the template matching the slug * * @param string $template_slug Slug of the template to retrieve. * * @return AbstractTemplate|AbstractTemplatePart|null */ public function get_template( $template_slug ) { if ( array_key_exists( $template_slug, $this->templates ) ) { $registered_template = $this->templates[ $template_slug ]; return $registered_template; } return null; } }