user2406735
user2406735

Reputation: 245

Wordpress remove or override action "template_redirect" from another plugin

The Woocommerce Subscriptions plugin is using a function called with action:

add_action( 'template_redirect', array( &$this, 'maybe_setup_cart' ), 100 );

I need to remove this action in my plugin, as it is causing unwanted effects.

I have tried creating an action before it in plugin construct, to override it:

add_action('template_redirect', array( &$this, 'maybe_setup_cart' ), 98);

In it i am also trying to remove the action:

remove_action( 'template_redirect', 'maybe_setup_cart', 100 );

This is also not working. How can i disable the action from another plugin?

Upvotes: 1

Views: 1334

Answers (1)

Sourabh Matolia
Sourabh Matolia

Reputation: 169

You can copy function shared here: https://github.com/herewithme/wp-filters-extras/blob/master/wp-filters-extras.php

Next simply do

remove_filters_with_method_name( 'template_redirect', 'maybe_setup_cart', 100 );

I tried and It works :)

Thanks

Upvotes: 1

Related Questions