vendredi 31 juillet 2015

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

  1. is in the tshirts category
  2. is in the tshirt category and the tshirt is tagged for men
  3. is in the tshirt category and the tshirt is tagged for women

3 templates, 3 scenarios.

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');  

    }

?>

Aucun commentaire:

Enregistrer un commentaire