Custom Conditions
You can extend PredictCart with custom condition types using the conditions controller.
Architecture
Conditions follow a registry pattern. The core condition types are registered in PredictCart_Conditions_Controller, which loads condition classes from the classes/conditions/ directory.
To add a custom condition, create a class that implements the condition evaluation interface and register it via the predictcart_init_controllers action.
Condition Class Structure
Each condition class should provide:
- A unique type identifier (e.g.,
my_custom_condition) - An
evaluate()method that accepts a condition config and cart data - A
get_label()method for admin display
Registration Example
add_action('predictcart_init_controllers', function() {
$controller = PredictCart_Conditions_Controller::get_instance();
$controller->register_condition('my_type', 'My_Namespace\My_Condition');
});
The condition system supports AND and OR matching via the rule's conditions_match_mode setting.