Templates WooCommerce-需要特定类别的php文件

Templates WooCommerce-需要特定类别的php文件,templates,woocommerce,Templates,Woocommerce,我想补充一点: 需要获取模板目录()/mytheme/folder/file.php' 对于WooCommerce中的特定类别,我已经尝试过: function get_file() { if( has_term( 'categoryName', 'product_cat' ) ) { require get_template_directory() . '/mytheme/folder/file.php'; } } add_action( 'woocommerce_before_main_c

我想补充一点:

需要获取模板目录()/mytheme/folder/file.php'

对于WooCommerce中的特定类别,我已经尝试过:

function get_file() {
if( has_term( 'categoryName', 'product_cat' ) )  {
require get_template_directory() . '/mytheme/folder/file.php';
}
}
add_action( 'woocommerce_before_main_content', 'get_file');
但它不起作用/ 如何仅为1个类别添加此文件? 或多猫。通过使用else if
您好,Gabrielle

我很惊讶您没有因为不存在的文件而收到PHP错误。但是请查看函数。它提供当前主题文件夹的路径。因此,我认为您的路径可能是错误的,因为您的主题文件夹正在重复。。。类似于
SOME\u PATH\u STUFF/wp content/themes/myteme/myteme/folder/file.php的东西

请尝试以下操作:

function get_file() {
if( has_term( 'categoryName', 'product_cat' ) )  {
require get_template_directory() . '/folder/file.php';
}
}
add_action( 'woocommerce_before_main_content', 'get_file');

这是一个模板文件还是有其他用途?我尝试将文件上传到我的WooCommerce商店,以进行价格验证,但仅将特定文件上传到特定类别