You are here:  » PT PHP - AND/OR terms for field IF


PT PHP - AND/OR terms for field IF

Submitted by CashNexus on Sat, 2019-08-31 14:30 in

Hello David,
In /html/product.php you use excellent IF construction what allows to show a field if, for example, field ["coupon"] is not empty
{code saved}

Is it possible to extend this code to print something detecting the values of TWO fields with OR/AND terms, for example
{code saved}
will print End Date if BOTH fields ["coupon"] AND ["voucher_code"] are not empty.

Another variant with OR, for example
{code saved}will print End Date if ANY of the fields ["coupon"] AND ["voucher_code"] are not empty.

Thanks in advance for the hint useful for all PT community !
Have a nice weekend !
Best regards,
Serge

Submitted by support on Mon, 2019-09-02 11:09

Hello Serge,

In PHP, logic AND is && and logic OR is || so you could use as the IF conditions, for example:

<?php if($product_main["voucher_code"] && $product_main["coupon"]): ?>

~or~

<?php if($product_main["voucher_code"] || $product_main["coupon"]): ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by CashNexus on Mon, 2019-09-02 12:44

Hello David, thank you very much, now I've catch the right syntax.
Let me extend a little my question to finalize the matter - what is correct code syntax for the condition - IF price equal to 0.00
<?php if($product_main["price=0.00"]: ?>

Submitted by support on Mon, 2019-09-02 13:13

Hi,

In PHP, "==" is the comparison operator, so you would use:

<?php if($product_main["price"] == "0.00"): ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by CashNexus on Mon, 2019-09-02 13:31

Dear David, thanks a lot for your support !
With such a small code changes your PriceTapestry is very flexible for content creation !
Best regards,

Submitted by CashNexus on Thu, 2019-11-14 08:12

Good morning, David !
One more question about this topic and PHP PT syntax - is it possible to detect the term IF EMPTY ?
Because

<?php if($product_main["voucher_code"] && $product_main["coupon"]): ?>

detects IF both fields are NOT EMPTY - then do something.
But how to use the same code but vise versa ? - IF both fields ARE EMPTY - then do something.
As always, thanks a lot in advance for a tooltip !
Best regards,
Serge

Submitted by support on Thu, 2019-11-14 08:54

Hello Serge,

Prefix each expression with "!" (the NOT) operator to detect if both empty, e.g.

<?php if(!$product_main["voucher_code"] && !$product_main["coupon"]): ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by CashNexus on Thu, 2019-11-14 10:26

Thanks a lot for the hint, everything works in a perfect way.
Have a nice day !
Best regards,
Serge