I want to add my own function to an already existing hook. Here is the definition:

do_action( 'woocommerce_before_single_product_summary' );

The original function that uses it looks like so:


Since I don't want to touch the theme, nor Woocommerce templates, I want to add my own function but with lower priority and some 3 extra parameters like so:

add_action( 'woocommerce_before_single_product_summary', 'my_own_function', 6,  3);
  • Is it possible?
    • If yes, where are these parameters defined?
  • If not,
    • Is it possible to use global values instead?
    • Is there another solution to my problem?

1 Answer 1



do_action( 'woocommerce_before_single_product_summary' );

doesn't have any additional input arguments like:

do_action( 'woocommerce_before_single_product_summary', $args1, $args2, $args3 );

then your action callback will always be called without any input arguments.

function my_own_function ()
    // ...

So you will have to get it by other means: e.g. through functions, classes or by tapping values from other hooks.

But you can surely change the priority:

add_action( 'woocommerce_before_single_product_summary', 'my_own_function', 5 );

If you can modify it, e.g. in your child theme, to:

do_action( 'woocommerce_before_single_product_summary', $args1, $args2, $args3 );

then you can use:

add_action( 'woocommerce_before_single_product_summary', 'my_own_function', 5, 3 );

with the callback as:

function my_own_function ( $args1, $args2, $args3 )
    // ... you have now access to $args1, $args2, $args3
  • Since its a plugin that I develop I can't use a child theme. I tried to use global variables but their value do not preserve in the time when the function is actually called. Is there a way to override it in the php level?
    – Izack
    Nov 21, 2016 at 8:20
  • Hard to say in general. You could try to write a class that collects those values you need, e.g. from various filters or actions, and then pass it on to the class method, that you use as an action callback for the woocommerce_before_single_product_summary hook. @Izack
    – birgire
    Nov 21, 2016 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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