Creating custom conditions

To create a custom condition you will need to create 2 files in these folders:

classes/conditions/
classes/condition-methods/

You can base your custom condition on something that already exists. For example, try to copy these 2 files:

classes/conditions/rp-wcdpd-condition-cart-coupons.class.php
classes/condition-methods/rp-wcdpd-condition-method-coupons.class.php

And rename those to something else, following the naming scheme, for example:

classes/condition-methods/rp-wcdpd-condition-method-test.class.php
classes/conditions/rp-wcdpd-condition-cart-test.class.php

Conditions are mostly what is presented in the UI, but it also can have the code to get the value. Condition methods are what drives the conditions comparison.

To correctly set those up, you will need to set the key for each and link them via options in the beginning of the file:

protected $key = 'coupons';
protected $contexts = array('product_pricing', 'cart_discounts', 'checkout_fees');
protected $method = 'coupons';

As you can see there’s $method variable, which points to the specific method.

Also, in the condition you will see get_value() and get_label() methods – those you can change however you want. In condition method you will need check() method, which will control how the pre-defined condition value is compared to the actual value in each case.

?