1

I have a custom module, in my module call commerce_discount_add_line_item() function, it exists in commerce_discount.rules.inc, this modules is installed correctly and status is enabled but when I call it returns:

( ! ) Fatal error: Call to undefined function commerce_discount_add_line_item().

It is strange, why has this happened?

5

By default inc files are not included(only module files are included). They should be called explicitly like below before making a call to a function in that file.

module_load_include('inc', 'commerce_discount', 'commerce_discount.rules');

Further Reading on inc files and how they differ from .module files : https://drupal.stackexchange.com/a/54069/4876

  • 1
    tnx , I tried this, but want to know why. tnx. – Yusef Feb 12 '14 at 6:36
  • 1
    You are faster than me. – Jayendra Kainthola Feb 12 '14 at 6:36
2

I hope you have included commerce_discount.rules.inc file in your module file.

You can use below code to include file, if you have not included files into your module file.

module_load_include('inc', 'commerce_discount', 'commerce_discount.rules');

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.