WC_Admin_Meta_Boxes::remove_block_templates()
Remove irrelevant block templates from the list of available templates for products. This will also remove custom created templates.
Method of the class: WC_Admin_Meta_Boxes{}
No Hooks.
Return
String[]
. Templates array excluding block-based templates.
Usage
$WC_Admin_Meta_Boxes = new WC_Admin_Meta_Boxes(); $WC_Admin_Meta_Boxes->remove_block_templates( $templates );
- $templates(string[]) (required)
- Array of template header names keyed by the template file name.
WC_Admin_Meta_Boxes::remove_block_templates() WC Admin Meta Boxes::remove block templates code WC 8.3.0
public function remove_block_templates( $templates ) { if ( count( $templates ) === 0 || ! wc_current_theme_is_fse_theme() || ( ! function_exists( 'gutenberg_get_block_template' ) && ! function_exists( 'get_block_template' ) ) ) { return $templates; } $theme = wp_get_theme()->get_stylesheet(); $filtered_templates = array(); foreach ( $templates as $template_key => $template_name ) { // Filter out the single-product.html template as this is a duplicate of "Default Template". if ( 'single-product' === $template_key ) { continue; } $block_template = function_exists( 'gutenberg_get_block_template' ) ? gutenberg_get_block_template( $theme . '//' . $template_key ) : get_block_template( $theme . '//' . $template_key ); // If the block template has the product post type specified, include it. if ( $block_template && is_array( $block_template->post_types ) && in_array( 'product', $block_template->post_types ) ) { $filtered_templates[ $template_key ] = $template_name; } } return $filtered_templates; }