• Hey guys,

    I have some trouble with removing the following:
    add_action( ‘woocommerce_email_after_order_table’, array( $this, ’email_after_order_table’ ), 10, 2 );
    add_filter( ‘woocommerce_get_order_item_totals’, array( $this, ‘order_item_totals’ ), 10, 2 );

    I tried (for removing the filter):
    remove_filter( ‘woocommerce_get_order_item_totals’, array( $this, ‘order_item_totals’ ), 10, 2 );
    remove_filter( ‘woocommerce_get_order_item_totals’, ‘order_item_totals’, 10, 2 );
    remove_filter( ‘woocommerce_get_order_item_totals’, ‘order_item_totals’, 10 );
    remove_filter( ‘woocommerce_get_order_item_totals’, ‘order_item_totals’);

    But nothing works..

    Any idea wat i’m doing wrong?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The function “remove_filter” is located in:
    wp-includes/plugin.php:
    It is declared as:
    function remove_filter( $tag, $function_to_remove, $priority = 10 ) {

    I think you mistake is in making the 2nd argument an array, this is necessary when adding the filter/action where the function belongs to a class and needs an object to act upon.

    Tim Nash

    (@tnash)

    Spam hunter

    The remove_filter has to know the specific function it is removing and the tag.

    In the example you have the add_filter is calling a function within the class it is in, this case a function order_item_totals. So you would need to do like wise, either extending the class, or making sure you call the class as well as the function.

    I correct myself, when calling remove_filter the 2nd argument MUST match the argument used when adding the hook/filter.
    So @dvbmedia, are you calling the remove functions from the same class and same object that was in the add hook/filter call.

    Thread Starter DVBMedia

    (@dvbmedia)

    No the remove function is called in another file. So if i understood it correctly i have to figure out which function is in: array( $this, ‘order_item_totals’ ) in order to remove it correctly?

    Other strange thing is when is use: remove_all_filters(‘woocommerce_get_order_item_totals’) it works. But when i try to do the same for: remove_all_actions(‘woocommerce_email_after_order_table’) it doesn’t work.

    Thanks for helping guys!

    So if i understood it correctly i have to figure out which function is in: array( $this, ‘order_item_totals’ ) in order to remove it correctly?

    You are close.
    Not quite “which function”, it is the object that the “$this” refers to that has to be the same, the same instance of the same class. It is hard to generalise, but is this object a global variable ? It may be necessary to save a reference to it near where you did the add_action.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Problem with removing filter and action’ is closed to new replies.