I know there are hundreds of action hooks available in Wordpress and in Woocommerce plugin, but what is most confusing to me is: when exactly they are invoked?
For some of the hooks there are some information available in the internet, but for many of them I do not see any information available.
For example when I was checking the code of some custom plugin, I see following hooks :
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'woocommerce_settings_api_form_fields_cod', array( $this, 'extend_cod' ) );
add_action( 'woocommerce_settings_api_sanitized_fields_cod', array( $this, 'clean_up_settings' ) );
add_action( 'woocommerce_delete_shipping_zone', array( $this, 'clean_up_gateway' ) );
My questions are where I can get the list of all the hooks for Woocommerce/Wordpress ? In the above example whether hooks starting with 'woocommerce_' are part of standard hooks or they are custom hooks specific to plugin ? Is it possible to create custom hooks ?
There are 2 kinds of hooks: Action hooks and filter hooks.
Hooks are added/created via do_action()
or apply_filters()
functions.
Hooks are triggered when the code where that do_action()
or apply_filters()
are located run.
You can attach a callback function to an existing hook using add_action()
or add_filter()
.
Note: There is also a lot of undocumented hooks like most of various composite hooks.
Related: