I have a problem with a plugin and WooCommerce.
So I have a plugin with an options page, and a custom checkbox on it.
When this checkbox is activated, I want to hide/remove the default WooCommerce related product container.
I can remove this container if I just add this code:
add_action( 'init', 'add_action_function');
function add_action_function(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
But the problem is that I need to call this function from inside another "add_filter" function.
In the moment I have something like this:
add_filter( 'woocommerce_after_single_product_summary', 'add_filter_function' );
function add_filter_function () {
// Get the plugin option
$active = get_option( 'prfx_active', 'no');
// If option value is "yes", remove the related products container
if ($active = 'yes') {
// I think this add_action call is wrong
add_action( 'init', 'add_action_function');
function add_action_function(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
}//END if $active = yes
// Do some other stuff here
}//END add_filter_function
But when I change the option in the admin-settings, nothing changes. So I think the "init" hook is not right here.
I cant find the right hook to make this work. What hook must I use when I want it to fire when the plugin options get updated?
Thanks in advanced, Mo
Thanks to Danijel and his answers.
I dont know why I didnt think of it this way. Maybe this was to much "action" for me on that late evening ;)
I now placed the "add_action" outside of the "add_filter" function and just do the conditional-check there.
This is working:
add_action( 'init', 'hide_related');
function hide_related () {
if ( get_option( 'prfx_active', 'no' ) == 'yes' ) {
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
};
add_filter( 'woocommerce_after_single_product_summary', 'add_filter_function' );
function add_filter_function () {
...