I'm trying to use a custom page for only one of the products in the woocommerce shop. I've been trying to apply the attached function but without success (which code is coming from this answer).
I have a created a copy of the single-product.php file in my /woocommerce folder with some added code, but the single product view only shows the "standard" single-product-php and not my single-product-mock.php file.
And the product does have the product category "custom".
add_filter( 'template_include', 'so_43621049_template_include', 10 );
function so_43621049_template_include( $template ) {
if ( is_singular('product') && (has_term( 'custom', 'product_cat')) ) {
$template = get_stylesheet_directory() . '/woocommerce/single-product-mock.php';
}
retur
The code that you are using works just perfectly. Your code is a bit incomplete too:
add_filter( 'template_include', 'custom_single_product_template_include', 50, 1 );
function custom_single_product_template_include( $template ) {
if ( is_singular('product') && (has_term( 'custom', 'product_cat')) ) {
$template = get_stylesheet_directory() . '/woocommerce/single-product-mock.php';
}
return $template;
}
So the problem could be related to:
Solutions:
single-product-mock.php
single-product.php
template inside the "woocommerce" folder located in your active child theme (or active theme)
One of those, should solve your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With