3

In the standard WooCommerce template file content-single-product.php there is a set of hooks that control the way the page lays out in a series of blocks which are called by a series of hooks eg 'woocommerce_before_single_product_summary'. If you are familiar with WooCommerce you will know what I mean.

There are three of these

  • woocommerce_before_single_product_summary
  • woocommerce_single_product_summary
  • woocommerce_after_single_product_summary

For my layout I need to add a fourth along the lines of 'woocommerce_before_single_product_intro'

I understand that I can move content around, such as moving the title to before the image. That seems to work fine, but I can't work out how to add a new hook.

I have tried adding add_action( 'woocommerce_single_product_intro', 'woocommerce_template_single_title', 5 ); to my functions file but it didn't work and I am guessing I have missed something rather important from it.

3

You can create a hook by calling do_action, then referring to the hook in your functions.php with add_action.

For example, in the theme, where you want the action to occur:

do_action('woocommerce_before_single_product_intro');

Then in functions.php

add_action('woocommerce_before_single_product_intro','your_function',[...]);

For the sake of maintainability, I'd choose a naming convention that doesn't confuse your hooks with WooCommerce's.

  • 1
    Thanks, worked a treat, and a good point about the naming convention, have taken that on board. – UntitledGraphic Feb 28 '16 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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