closer12 Posted March 10, 2015 Posted March 10, 2015 Hi. i am using the code below for showing price1 field if empty i show other text. But i need code if price1 is empty show price2 if both is empty show the text.. how i can do that i need help with php code? if ($item->price1) { echo 'From: € ' . $item->price1 ;} else { echo 'please ask'; }
ESRCH Posted March 10, 2015 Posted March 10, 2015 Well the easiest way seems to simply use an else if: if ($item->price1) { echo "From euros {$item->price1}"; } else if ($item->price2) { echo "From euros {$item->price2}"; } else { echo 'please ask'; } 3
teppo Posted March 10, 2015 Posted March 10, 2015 You can always just store the values to variable and see if it's filled. Also, note that PW provides a native way (shortcut, really) for getting the first non-empty field value: $item->get("field1|field2|field3") etc. // like this: $price = $item->get("price1|price2"); if ($price) echo "From: € " . $price; else echo "please ask"; // this works too: $price = $item->get("price1|price2"); echo $price ? "From: € " . $price : "please ask"; 2
ESRCH Posted March 10, 2015 Posted March 10, 2015 I had forgotten about the $item->get('field1|field2') syntax, thanks for the reminder, it's really useful!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now