How to remove filter added by another plugin in a class

You did not write where you put the filter removal code, but I suspect you tried to delete it before it was added. Another important point, you have not given the priority parameter in remove_filter().

Quote from the documentation:

remove_filter( $tag, $function_to_remove, $priority );

Important: To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.

Try removing filter when the plugins are already loaded and enter both required parameters – function name and priority.

add_action( 'plugins_loaded', 'se334421_remove_plugin_filter' );
function se334421_remove_plugin_filter() {
    remove_filter( 'woocommerce_cart_item_subtotal', 'WC_Subscriptions_Switcher::add_cart_item_switch_direction', 10 );
}

Leave a Comment