Woocommerce 单品 - 模板分类 [英] Woocommerce single product - template by categories

查看:22
本文介绍了Woocommerce 单品 - 模板分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经发布了问题但对我不起作用,所以我想请一些帮助...;)

Already posted question but not working for me, so I'm asking a little help guys... ;)

有我的 single-product.php(woocommerce 文件行:28)

 <?php if ( is_product_category( 'customcateg' ) ) 
    {
       woocommerce_get_template_part( 'content', 'single-product-customcateg' ); }
else {      
       woocommerce_get_template_part( 'content', 'single-product' ); } 
  ?>

我的主题/woocommerce 中有 3 个文件:

I have in my theme/woocommerce 3 files:

  • single-product.php
  • content-single-product.php
  • content-single-product-customcateg.php

文件包含不同的 php 代码(customcateg 必须防止访问者和一些角色;这部分已经完成...)

The files contains different php codes (the customcateg has to be protected from visitors, and some roles; this part is already done...)

当我尝试访问customcateg"中的产品时,它向我显示了正常的单一产品"模板....

When i try to access a product who is in "customcateg", it shows me the normal "single-product" template....

我试着放:

 <?php if ( is_product_category( 'customcateg' ) ) 
    {
       woocommerce_get_template_part( 'content', 'single-product-customcateg' ); }
else {      
       woocommerce_get_template_part( 'content', 'single-product-customcateg' ); } 
  ?>

它只是显示单个产品,但它必须显示 customcateg 一个,但它没有.只有当我将single-product-customcateg.php"内容放在single-product.php"中时才会这样做......

It simply show the single-product, but it has to show the customcateg one, but it does not. It only does when I pust the "single-product-customcateg.php" content in the "single-product.php" ...

你们怎么了?

请帮助我:)

非常感谢,

推荐答案

它正在寻找一个名为 content-single-product-customcateg.php 的文件

It's looking for a file titled content-single-product-customcateg.php

那个文件不存在,所以它回退到默认值.

That file doesn't exist so it's falling back to the default.

if ( has_term( 'customcateg', 'product_cat' ) ) {
    woocommerce_get_template_part( 'content', 'single-product-customcateg' );
} else {
    woocommerce_get_template_part( 'content', 'single-product' );
}

可以顺便添加一下你的content-single-product-customcateg.php的内容吗?

Can you add the contents of your content-single-product-customcateg.php by the way?

这篇关于Woocommerce 单品 - 模板分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆