2

I have a plugin that hooks a function on to the woocommerce_before_my_account action. I would like instead for the plugin to hook that function to the woocommerce_after_my_account action.

If I create my own plugin, is it possible to achieve this? If so, how?

Thanks

3

You can use the remove_action() function to unhook a function from an action and then add_action() to hook it elsewhere. Note that when removing an action you must specify the tag (hook name), function, and priority exactly as it was added.

Edit: Here are some additional details:

You'll have to look at the source of the other plugin to determine how to do that. Without specific information about which plugin and function you're talking about we can't give you an exact answer, but here's an example:

if the plugin hooks the function like this:

add_action( 'woocommerce_before_my_account', 'function_to_move', 10 );

you would do something like:

function my_move_woo_functions() {
    remove_action( 'woocommerce_before_my_account', 'function_to_move', 10 );
    add_action( 'woocommerce_after_my_account', 'function_to_move', 10 );
}
add_action( 'plugins_loaded', 'my_move_woo_functions' );

The important part is that you have to move the action after their hook is created but before the hook is run.

  • Thanks. I'm aware of the functions, but as the function that I need to hook to the woocommerce_after_my_account action is in another plugin, I don't know how I can access it. i.e. how do I say "get this function from this plugin and hook it to this action"? – Pete H Jan 11 '16 at 10:43
  • Additional details added to my additional response. – Scott Nelle Jan 14 '16 at 15:02
  • Just to underline @ScottNelle 's clear answer, it doesn't matter where in your plugins, theme or even core that the replacement function is defined, as long as it is defined somewhere. – Andy Macaulay-Brook Jul 27 '16 at 16:04

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.