0

I Have written a shipping method (name:X) and a payment method(name:Y) for drupal commerce. the problem is that I want to force user to pay with Y if he selects X and I want to disable other payment methods on this condition.

it can manually be done with rules! but I want to programmatically add this limit. how can I do it? is there a hook or something else?

2

You've already realized that you need a rules condition, since the available payment methods are determined through rules.

The selected shipping method is stored on the order entity ($order->shipping_rates), so you can just check that. You might need to write a custom Rules condition (which is just a PHP function declared by an implementation of hook_rules_condition_info()).

0

Depending on what you're trying to do you might want to reflect these restrictions in your form with javascript too, but essentially you probably just want to add some extra logic in your form validation or form submit handlers.

They aren't hooks, but are callbacks added in hook_form_alter().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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