remove filter which calls a public static function

I want to remove a filter which is added from within a public static function of a plugin class.

The filter is defined here (within the WCSG_Cart class, part of a plugin):

public static function init() {
  add_filter( 'woocommerce_cart_item_name', __CLASS__ . '::add_gifting_option_cart', 1, 3 );

and the class is a singleton class – WCSG_Cart::init() is called immediately after the class is defined.

In my theme’s functions.php file, I have

remove_filter('woocommerce_cart_item_name', array( WCSG_Cart::init(), 'WCSG_Cart::add_gifting_option_cart'), 99);

Which seems to make no difference.

As per this post suggestion, I have tried wrapping my remove_filter call in a function and adding it to the init action and that didn’t work:

add_action('init', 'do_something', 99);
function do_something() {
  remove_filter('woocommerce_cart_item_name', array( WCSG_Cart::init(), 'WCSG_Cart::add_gifting_option_cart'), 99);

I have also tried using just the class name as a string ('WCSG_Cart') in the array, and removing the WCSG_Cart:: from the function name, to no avail.

I can’t find any examples online of using remove_filter on a function that uses the __CLASS__ variable.

Any help is appreciated!

Read more here: remove filter which calls a public static function

Leave a Reply

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