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?

2 Answers 2

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

2
  • 1
    tnx , I tried this, but want to know why. tnx.
    – Yuseferi
    Commented Feb 12, 2014 at 6:36
  • 1
    You are faster than me. Commented Feb 12, 2014 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 and acknowledge you have read our privacy policy.

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