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
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.