Today I was working on a feature on a site that was using Ubercart's uc_roles module. By default, whenever a customer would buy a product with a role attached to it, an email would be generated stating what role that customer bought. However, in my use case, we did not want these emails generated and we needed to keep our settings in code. So, the question was, how do I disable another module's rules from my own module? After Jedi mind tricks failed, I came across the solution in the Rules API and the function hook_default_rules_configuration_alter.
To disable rules from within a module
- First, add a new file to your module named "MY_MODULE.rules_defaults.inc", replacing MY_MODULE with your own module's name.
- Within the file you just created add the following function:
/** * Implements hook_default_rules_configuration_alter(). */ function bfa_instructor_listings_default_rules_configuration_alter(&$configs) {}
- Then, you need to get the machine name of the rule you want to disable. If you go to the rules admin screen, underneath the name is the machine name.
- Once you have the machine name, go back to your hook_default_rules_configuration_alter function and add the following to the function:
$configs['uc_role_notify_grant']->active = FALSE;
- So, my final code to disable all uc_role emails rules looked like this:
/** * Implements hook_default_rules_configuration_alter(). */ function MY_MODULE_default_rules_configuration_alter(&$configs) { $configs['uc_role_notify_grant']->active = FALSE; $configs['uc_role_notify_revoke']->active = FALSE; $configs['uc_role_notify_renew']->active = FALSE; $configs['uc_role_notify_reminder']->active = FALSE; }