My question conserns the Woocommerce plugin.
As you know we can create a custom single-page.php within our theme provided it is inside woocommerce subfolder.
What I need is the ability to have the single-product.php file inside my plugin.
I have tried a lot of ways and it works for other pages, for example I can redirect single-product/title.php to another page but I have had no luck redirect single-product.php.
I understand I probably can redirect it through httaccess file but what I need is redirecting the file through a plugin.
It seems that woocommerce specifies the template file after template_include hook.
So far I managed to use woocommerce_locate_template filter to redirect to some files but for single-product.php there seems to be a complete different story.
Any idea how I can have my own single-product.php inside my custom plugin?
UPDATE: I tried the solution given by one of the answer as follow:
add_filter('single_template', 'my_custom_template');
function my_custom_template($single) {
global $post;
if ( $post->post_type == 'product' ) {
echo 'test';// So its here
return plugin_dir_url( __FILE__ ).'woocommerce/single-product.php';
}
return $single;
}
The single-product page still goes to the default woocommerce template pages.
/woocommerce/single-page.php
and all other files within/woocommerce/
(inside theme folder) work with WooCommerce logic./single-product.php
is default WordPress logic (aka template hierarchy). So the solution from the linked answer should work here as well