template_include 停止处理 woocommerce 更新

template_include stop working on woocommerce update

以下代码用于覆盖产品详细信息页面模板,自上次更新 WooCommerce 以来它一直在工作。任何人都可以帮我解决这个问题,在此先感谢。

    add_filter('template_include', 'wpautomate_plugin_templates');
    function wpautomate_plugin_templates( $template )
    {   
        $plugin_path='';
        $reflector = new ReflectionClass('Ze_Single_Product_Layout');
        $file_name=plugin_dir_path($reflector->getFileName());
        $plugin_path=$file_name;
        $post_types = array('product');
        $template_id=get_post_meta( get_the_ID(), '_product_layout', true );
        if (is_singular('product') && !empty($template_id))
        {
            //render custom template  for single product
            $template = $plugin_path . 'template/woo-single-page.php';
        }
        return $template;           

    }//end of function

你需要调用这个过滤器

add_filter('template_include', 'wpautomate_plugin_templates');

带有init动作挂钩

add_action('init','load_custom_template_woo');
function load_custom_template_woo(){
  add_filter('template_include', 'wpautomate_plugin_templates');
}

谢谢

对我来说,我必须将钩子回调的优先级设置为大于 10,就像这样

// priority = 11
add_action('template_include', 'wpautomate_plugin_templates', 11);