我想为相关的产品类别设置不同的模板。我更改了 single-product.php 文件
if (is_product_category( 'first-category' )) {
woocommerce_get_template_part( 'content', 'single-product' );
}else{
woocommerce_get_template_part( 'content', 'single-product-other' );
}
仍在加载 content-single-product-other.php 文件内容。我确定检查了产品的类别
最佳答案
如果您将 single-product-other.php 放入 (yourtheme/woocommerce/) 文件夹并将 single-product.php 放入插件文件夹,就会发生这种情况。 您所要做的就是将两个模板都放在主题的 woocommerce 文件夹中(这是自定义原始代码的正确方法)。
仍然如果它不起作用然后尝试替换您的代码
woocommerce_get_template_part( '内容', '单一产品' );
有了这个。 wc_get_template_part( '内容', '单一产品' );
关于php - Woocommerce 不同的产品模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35682939/