How to remove filter added by another plugin in a class

Ok I’m struggling here – I feel this should be straightforward but I’m just not able to get it to work.

I need to remove a filter added by Woocommerce Subscriptions. The filter is part of the WC_Subscriptions_Switcher class found in class-wc-subscriptions-switcher.php and is added as below

class WC_Subscriptions_Switcher {

* Bootstraps the class and hooks required actions & filters.
* @since 1.4
public static function init() {

// Display/indicate whether a cart switch item is a upgrade/downgrade/crossgrade
add_filter( ‘woocommerce_cart_item_subtotal’, __CLASS__ . ‘::add_cart_item_switch_direction’, 10, 3 );

The function adds text to the cart (either (Upgrade), (Downgrade) or (Crossgrade) which I don’t want/need to be displayed in my case.

I have tried simply using the remove filter function as below from the WordPress Codex however the text in question is still displayed regardless.

global $WC_Subscriptions_Switcher;
remove_filter( ‘woocommerce_cart_item_subtotal’, array($WC_Subscriptions_Switcher, ‘add_cart_item_switch_direction’) );

I have also tried everything (I think) I found at the below answer and also simply tried the below from the
remove_action or remove_filter with external classes?

How do I remove this filter so that it’s not fired in the first place? I know I could override the text using gettext but I think it’s cleaner to not have it run in the first place (and even using gettext the html tags added by the filter will remain).

Any help appreciated.

Read more here:: How to remove filter added by another plugin in a class

Leave a Reply

Your email address will not be published. Required fields are marked *