Programmatically add condition to a rule and save it

Public
</> CopyGet raw version
php
  1. /**
  2. * Implements hook_update_N().
  3. * Add condition to the name_of_rule rule.
  4. */
  5. function hook_update_N() {
  6. // For more examples see http://www.drupalcontrib.org/api/drupal/contributions!rules!rules.api.php/7
  7. // https://www.drupal.org/node/1675748
  8. $rules_config = rules_config_load('rules_update_membership');
  9. $rules_config->active = TRUE;
  10. $rules_config->weight = 6;
  11.  
  12. $settings = array(
  13. 'data:select' => 'commerce-order:uid',
  14. 'op' => '==',
  15. 'value' => 0,
  16. );
  17. $rules_config->condition(rules_condition('data_is', $settings)->negate());
  18. $rules_config->save();
  19. }