Override woocommerce loop-start.php from theme using plugin?

Question

My theme has an override for /wp-content/themes/THEMENAME/woocommerce/loop/loop-start.php.
I want to override this file using a plugin. I understand it can be done using a child theme, but I want to use a plugin (because I have many other modifications bundled inside 1 plugin).

I found some other simular questions on stack exchange but couldn’t get to a working solution. Here are my attempts:

Using theme_file_path:

add_filter( 'theme_file_path', 'override_woocommerce_loop_template', 9999);

function override_woocommerce_loop_template( $path, $file = '' ) {
    if( 'woocommerce/loop/loop-start.php' === $file ) {
        $path = plugin_dir_path( __FILE__ ) . 'includes/woocommerce/loop/loop-start.php';
    }
    return $path;
}

Using template_include:

add_filter('template_include', 'override_woocommerce_loop_template', 9999);

function override_woocommerce_loop_template($template){  
    if( 'woocommerce/loop/loop-start.php' === $template ) {
        $template = plugin_dir_path( __FILE__ ) . 'includes/woocommerce/loop/loop-start.php';
    }   
    return $template; 
}

Any hints where I am wrong? Many thanks! 🙂

0
, , TVBZ 3 years 2020-06-04T10:10:30-05:00 0 Answers 93 views 0

Leave an answer

Browse
Browse