4

The following code is to override the Product Details page template, It was working since the last update on WooCommerce. Can anyone help me out on this, thanks in advance.

    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
Tristup
  • 3,603
  • 1
  • 14
  • 26

2 Answers2

2

You need to call this filter

add_filter('template_include', 'wpautomate_plugin_templates');

with init action hook

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

Thanks

Souvik Sikdar
  • 777
  • 5
  • 11
0

For me, I had to set the priory for the hook callback greater than 10, like this

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

Faraz Ahmad
  • 515
  • 1
  • 6
  • 13