简体   繁体   English

Woocommerce产品类别中的IF声明

[英]IF Statement in Woocommerce product category

I've been trying for a while now to try and make the code below work but i think im missing something obvious. 我已经尝试了一段时间,尝试使下面的代码工作,但我认为我缺少明显的东西。

I'm using Woocommerce and i'm basically looking to add a php file into the category based on criteria 我正在使用Woocommerce,我基本上是想根据条件将php文件添加到类别中

  1. is in the tshirts category 在t恤类别中
  2. is in the tshirt category and the tshirt is tagged for men 在t恤类别中,并且t恤被标记为男性
  3. is in the tshirt category and the tshirt is tagged for women 在t恤类别中,并且t恤被标记为女性

3 templates, 3 scenarios. 3个模板,3个场景。

I'm sure there is a more elegent way to do this. 我敢肯定,有一种更优雅的方法可以做到这一点。 Apologies for the rookie question but i really did look this up. 为菜鸟问题道歉,但我确实确实对此表示怀疑。

<?php
    $tshirt = (has_term('tshirt', 'product_cat'));
    $men = (has_term('men', 'product_tag'));
    $women = (has_term('women', 'product_tag'));

    if (($tshirt = '1') && ($men = '') && ($women = '')){
    include ('template1.php'); 
    }
    elseif (($tshirt = '1') && ($men = '1') && ($women = '')) {
    include ('template2.php'); 
    }

    elseif (($tshirt = '1') && ($men = '') && ($women = '1')) {
    include ('template3.php');  

    }

?>

In all of your if else if conditions you need to use comparison parameter == and not assignment operator = 在您所有的if else if条件你需要使用比较参数==而不是赋值运算符=

if (($tshirt = '1') && ($men = '') && ($women = '')){

should be 应该

if (($tshirt == '1') && ($men == '') && ($women == '')){

same to be continued over else if statement else if声明,将在else if继续

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM