Conditional Statements with custom function
-
Hi all,
I am trying to create a conditional statement for a json file I receive form a Dealer Management system to sync the data between the site and the system.
To give a background the site has 6 taxonomies for Makes of Vehicle, 5 of which are branded. They are Alfa, Jeep, Suzuki, Fiat, Fiat Pro and Other-Makes. The Json file i receive however doesn’t quite match the taxonomies in that it doesn’t group the none branded makes into Other-makes instead it uses their actual make for example, Nissan, Toyota etc. The second problem is that the Fiat Vehicles are all grouped under Fiat instead of being split between their normal and professional ranges.
So what I need to do is create conditional statement for the make taxonomy that
1) Checks if the entry is an Alfa, Jeep, Suzuki or Fiat if it is then it gets the value from the Json file otherwise it gets given the value Other-Make.
2) Checks to see if the vehicle is a Fiat or Fiat Pro, the only way to do this is to check if the vehicle model belongs to the Fiat Pro range and if it does then it gets the value Fiat Pro otherwise it gets the value Fiat.
What I have done so far:
1) I have managed to create a function to check the make and assign Other-Makes like so :
function ae_make($Importmake) { if (($Importmake == "ALFA ROMEO") or ($Importmake == "JEEP") or ($Importmake == "SUZUKI") or ($Importmake == "FIAT")) : $x = $Importmake; else: $x = "Other-makes"; endif; return $x; }
and in the wp-all-import category field I have used this [ae_make({make[1]})] which works perfectly
2) Trying to check if the vehicle is Fiat or Fiat Pro is proving tricky. I have tried creating a second function that checks the model variable and returns a value. On its own it works.
However I am not sure how to check both conditions are meet within the category field. I tried using the inbuilt conditional statements in WP all import like this… [IF({ae_model({model[1]})[contains(.,’Fiat Pro’)]})]FIAT PRO [ELSE][ae_make({make[1]})][ENDIF]
But the syntax is wrong and I am not even sure if it is possible to go this route.3) I have also tried creating an advanced condition custom function which accepts two variable inputs and returns one value using this call [ae_make({make[1]}, {model[1]})]
I am not sure if that is even allowed or if the code below is correct.function ae_make($Importmodel, $Importmake) { if (($Importmake == "ALFA ROMEO") or ($Importmake == "JEEP") or ($Importmake == "SUZUKI") or ($Importmake == "FIAT")) : $x = $Importmake; elseif ($Importmake == "FIAT" && ($Importmodel == "FULLBACK" || $Importmodel == "FIORINO" || $Importmodel == "DOBLO CARGO" || $Importmodel == "DOBLO PANORAMA" || $Importmodel == "DUCATO")): $x = "Fiat-Pro"; else: $x = "Other-makes"; endif; return $x; }
If you could possibly point me in the right direction that would be great. Either using a custom function or if the inbuilt If conditionals allow for multiple conditions that could also work. Something like this perhaps?
[IF({model[contains(.,’FULLBACK’) or (.,’DOBLO PANORAMA’) or (.,’DOBLO CARGO’) ]})]
Fiat Pro
[ELSE]
[ae_make({make[1]})]Any assistance would be appreciated.
Thanks
- The topic ‘Conditional Statements with custom function’ is closed to new replies.