12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Jul 26, 2020

How to turn any if/else statement into an Oxygen Condition (EDD example)

David Browne

There are essentially infinite number of possible conditions to add to Oxygen with the API. This members-only tutorial will walk through the logic of creating your own condition if you already know the if/else PHP conditional statement and want to add as an option in the conditions dropdown.

Note - for many things we can easily achieve the same thing by using the 'PHP function return value' option by adding in the name of a function that will return true or false. But if you find yourself needing to use same type of condition multiple times and want as a seperate condition without having to remember function names, this is how to do it.

We already have a tutorial that goes through the best way to set up a new condition in Oxygen, this will be more of a walkthrough with three examples of some starting PHP condition statements and how to arrive at the finished code that registers as a new condition in Oxygen.


We'll go through three examples, from simple to more complicated. The main thing to remember is that Oxygen conditions are implemented in a way which means 'if this function returns true, show the element'.

We'll look at these examples..

  • The first will be using a simple function that is either true or false. (is the user logged in?)
  • The second will be a function with one parameter that the user must input. (has the user purchased this particular download?)
  • The third will be a custom function that compares two values. (did the user register their account after this event end date?)

Example 1

For the simplest example we'll use one of the WordPress functions to recreate an existing condition in Oxygen - is the user logged in?

Here's how the function would be used as a regular conditional statement..

if ( is_user_logged_in() ) {
    echo 'User is logged in';        // if true
} else {
    echo 'User is not logged in';    // if false

We'll turn this into an Oxygen condition.

When registering a new condition, the first part is just about choosing the name, category, what values should the user be choosing from and then just giving the callback function a name.

The second part is the actual callback function and is the important part as this is the part that will determin if the element is displayed (if the callback function returns true the element will be displayed).

Register the Condition

Here is the first part to register the condition in Oxygen. For brevity, I've simplified the code and only added comments to highlight the decisions and add some explanations.

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.