Skip to main content
2 of 2
added 90 characters in body

Add my own function to existing WooCommerce hook

I'm trying to customise my WooCommerce child theme with parent theme Storefront. The parent theme creates single product template (content-single.php) like this:

/**
 * @hooked storefront_post_header - 10
 * @hooked storefront_post_meta - 20
 * @hooked storefront_post_content - 30
 */
do_action( 'storefront_single_post' );

and these functions are hooked to build out the page (/inc/structure/hooks.php):

add_action( 'storefront_single_post', 'storefront_post_header', 10 );
add_action( 'storefront_single_post', 'storefront_post_meta', 20 );
add_action( 'storefront_single_post', 'storefront_post_content', 30 );

For reference, this is the storefront_post_header function (inc/structure/post.php):

if ( ! function_exists( 'storefront_post_header' ) ) {
/**
   * Display the post header with a link to the single post
   * @since 1.0.0
 */
function storefront_post_header() { ?>
    <header class="entry-header">
    <?php

    if ( is_single() ) {
        storefront_posted_on();
        the_title( '<h1 class="entry-title" itemprop="name headline">', '</h1>' );

    } else {
        if ( 'post' == get_post_type() ) {
            storefront_posted_on();
        }

        the_title( sprintf( '<h1 class="entry-title" itemprop="name headline"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h1>' );
    }
    ?>
    </header><!-- .entry-header -->
    <?php
}

I want to output my function, storefront_post_header_categories (below), after storefront_post_header. I thought I would be able to add the following to my child theme functions.php to do that :

add_action( 'storefront_single_post', 'storefront_post_header_categories', 15 );
function storefront_post_header_categories() {
  echo "code to display categories here";
}

This doesn't work, or output anything to the front-end. Nor does is give a WP_DEBUG error.

What am I doing wrong? Thanks for your help and let me know if you need any more info.