Seyong Cho
Seyong Cho

Reputation: 1087

Wordpress WooCommerce Storefront Theme - Where are functions defined?

I'm new to WooCommerce and Storefront theme. I am trying to get a sense of the source code before I start modifying it. I'm just having a little difficulty finding out where all the necessary codes are located.

When I open the header.php, I got lost because every functions were hooked to some other files like this.

do_action( 'storefront_before_header' );

Where are these functions defined in Storefront theme? and how can I find where all these do_action functions are defined in the future other than just opening all the files are searching for the strings?

I've looked into files such as:

Upvotes: 3

Views: 1420

Answers (1)

Minh Tri
Minh Tri

Reputation: 2471

For all woocommerce-related products, there's a @hooked tag in phpdoc block before each hook. If there're no @hooked tags, that hook is just a reserved hook which may be used in the future.

Let's see the storefront_header hook:

/**
 * Functions hooked into storefront_header action
 *
 * @hooked storefront_skip_links                       - 0
 * @hooked storefront_social_icons                     - 10
 * @hooked storefront_site_branding                    - 20
 * @hooked storefront_secondary_navigation             - 30
 * @hooked storefront_product_search                   - 40
 * @hooked storefront_primary_navigation_wrapper       - 42
 * @hooked storefront_primary_navigation               - 50
 * @hooked storefront_header_cart                      - 60
 * @hooked storefront_primary_navigation_wrapper_close - 68
 */
do_action( 'storefront_header' );

After the @hooked tag is a function name and priority in which the function is executed when the action is fired. Lower numbers correspond with earlier execution.

Most of the functions hooked to the hook is located inside storefront-template-functions.php and added inside storefront-template-hooks.php.

You can find those functions with simple IDE searchs inside theme folder.

Upvotes: 1

Related Questions