I can't seem to find any documentation on this so maybe someone here can help. I have been adding all my WooCommerce hooks to my functions.php file but I would rather have all of them in a separate file to keep things tidy. Obviously I will need another php file for these but how do I link it to the functions.php file so that the code runs as it does now? Thanks
Asked
Active
Viewed 585 times
2 Answers
1
just create new file with your woocommerce hooks code name anything what u want.
Ex. woocommercehook.php
and place file in theme folder.
in function.php file just include your woocommercehook.php
file at last.
include("woocommercehook.php");
Done. all work same as early.

Mahipal Patel
- 543
- 3
- 15
1
The PHP include/include_once and require/require_once will work fine. However,
create another file with your hooks( woo-hooks.php
) and use WP get_template_directory to require the file.
require get_template_directory() . '/woo-hooks.php';

omukiguy
- 1,401
- 3
- 17
- 36
-
Why use require get_template_directory() . '/woo-hooks.php'; over include("woocommercehook.php"); ? – Reece Dec 08 '17 at 11:34
-
The require() function is identical to include(), except that it handles errors differently. If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop. Reference: https://stackoverflow.com/questions/2418473/difference-between-require-include-and-require-once require get_template_directory() - Returns an absolute server path (eg: /home/user/public_html/wp-content/themes/my_theme) ref: https://developer.wordpress.org/reference/functions/get_template_directory/ – omukiguy Dec 08 '17 at 11:41