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!

1 Answer 1


remove_filter is supposed to be called with the same priority as the add_filter, so in this case you may want to replace 99 with 1, 3

remove_filter( 'woocommerce_cart_item_name', …, 1, 3 );

  • brilliant - that did the trick. Just for reference - I didn't need to wait for init to run, or use the WCSG_Cart:: prefix in the call: remove_filter('woocommerce_cart_item_name', array( 'WCSG_Cart', 'add_gifting_option_cart'), 1,3);
    – dafyddPrys
    Commented Apr 3, 2017 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.