2

I've been able to add a condition to an existing rule, but I can't find any documentation on how to modify an existing condition on a rule. The following code works for adding but I need to modify the one that already exists. Any ideas?:

$hk_delivery_rule = rules_config_load('commerce_shipping_service_hong_kong_delivery');

$hk_delivery_settings = array(
    'first_price:select' => 'commerce-order:commerce-order-total',
    'operator' => '<',
    'second_price' => array(
      'amount' => $hk_threshold,
      'currency_code' => 'HKD'
    )

  );

$hk_delivery_rule->condition(rules_condition('commerce_price_compare_price', $hk_delivery_settings));
$hk_delivery_rule->save();

1 Answer 1

3

So turned out it was quite easy:

  $hk_delivery_rule = rules_config_load('commerce_shipping_service_hong_kong_delivery');

  foreach ($hk_delivery_rule->conditions() as $condition) {

    if (isset($condition->settings['second_price'])) {

      $condition->settings['second_price']['amount'] = $hk_threshold;

    }

  }

  $hk_delivery_rule->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.