lkSuperboy
Posted on: 3 years ago

How force custom template file to a post type

WordPress php force custom template file to a post type


                                          add_filter( 'single_template', function( $template ) {
	global $post;
	if ( $post->post_type === 'product' ) {
		$locate_template = locate_template( array("woocommerce/template-product.php") );
		if ( ! empty( $locate_template ) ) {
			$template = $locate_template;
		}
	}
	load_template($template);
} );