Using a custom single product template for a specific product category in Woocommerce

限于喜欢 提交于 2019-12-04 18:42:18

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:

  1. The location of that custom template, that should be in a 'woocommerce' folder inside your active child theme (or inside your active theme).
  2. Woocommerce support need to be enable for your theme.

Solutions:

  1. be sure that inside your active child theme (or active theme) there is a "woocommerce" folder and add inside it your custom template single-product-mock.php
    (but not inside a "templates" sub-folder)
  2. To check Woocommerce support is enabled:
    • Copy the default single-product.php template inside the "woocommerce" folder located in your active child theme (or active theme)
    • Go in backend Woocommerce > Status … and you will normally see in "templates" section (at the end of this page):

      With an active child-theme:

      With an active theme:

    • If is not enable, you should search and look to the related Woocommerce documentation.

One of those, should solve your issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!