Hi, svenddv, I’m another WooCommerce user.
You can look into the conditional tag is_product() and use it in conjunction with the template_include hook.
Here is the developer documentation page for the hook: https://developer.wordpress.org/reference/hooks/template_include/
Here is the the WooCommerce documentation page for conditional tags: https://docs.woocommerce.com/document/conditional-tags/
Hi Ian,
Thanks for your reply! I really appreciate it.
I’m having trouble getting the template_include hook to work even without conditions, just trying to see if my code has any impact at all but it doesn’t do anything.
add_filter( 'template_include', 'demo_page_template');
function demo_page_template($template) {
if ( is_page( 'single-product.php' ) ) {
$template = $this->plugin_path . 'templates/woocommerce/single-product.php';
}
return $template;
}
any ideas?
as always, thanks!
Hi @svenddv,
Thanks for sharing further details and the code you’re trying to implement.
Have you tried using the is_product() WooCommerce tag for the single product page rather than single-product.php?
Hi @wpniall,
thanks for the suggestion but it doesn’t seem to work.
this is how I’ve tried it :
add_filter( 'template_include', 'demo_page_template');
function demo_page_template($template) {
if ( is_page( is_product() ) ) {
$template = $this->plugin_path . 'templates/woocommerce/single-product.php';
}
return $template;
}
I’ve also tried it this way :
add_filter( 'template_include', 'demo_page_template');
function demo_page_template($template) {
if ( is_product() ) {
$template = untrailingslashit( plugin_dir_path( __FILE__ ) ) . 'templates/woocommerce/single-product.php';
}
return $template;
}
still not seeing any effect.
-
This reply was modified 4 years, 8 months ago by
svenddv.
-
This reply was modified 4 years, 8 months ago by
svenddv.
Hi @svenddv
This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.
I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.
You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.