I’m trying to add a basic IF-statement to a PHP code snippet but my PHP knowledge is very limited and I didn’t have much success until now (I tried different variations on IF-statements which I found in other code snippets but without much success).
The company who originally created the code explained me where to add the IF-statement, what kind of IF-statement I need and also told me I should work with the variable called $coupon (this variable contains the name of the coupon).
The instructions are shown here in Green: https://www.diffchecker.com/EAk0Gz9u/
I understood it should be a very easy line of code to write for a PHP developer but I didn’t have much success until now since my PHP knowledge is VERY limited.
Is there maybe someone in this amazing community who can help me with this?
Thank you so much in advance!
Luke
2
Answers
As per the instruction you need to check if the coupon code begins with ‘affiliate-credit’ or not. If yes then the IF statement should return true.
To do so you need to check
$coupon
if it begins with ‘affiliate-credit’ or not. [As we can see the value of$coupon
is set byaffwp_get_coupon( $coupon->code )
function]The following might help you achieve this goal:
How to check if a string starts with a specified string?
If you can share some sample output values of
$coupon
here, that would be helpful.Of course, I’d be happy to help you add the IF-statement to your PHP code snippet!
Based on the instruction you provided, it seems that you need to add a simple IF-statement to check the value of the $coupon variable and execute certain code based on its value. Here’s the code snippet with the IF-statement added: