Shtarley
Shtarley

Reputation: 391

Disable hook/function loaded by a plugin

A wordpress plugin I'm using is loading the following code (which disables my add to cart button), and I need this code removed so that my add to cart button won't get disabled by the plugin.

I need a way to do this without editing the actual plugin files.

Here is the code responsible (the code that I need to remove):

// Remove default variable product add to cart
add_action('plugins_loaded', 'remove_variable_product_add_to_cart');
function remove_variable_product_add_to_cart()
{
    remove_action('woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30);
}

I tried adding the following to functions.php (but it didn't work)

remove_action('plugins_loaded', 'remove_variable_product_add_to_cart');

I also tried adding a priority:

remove_action('plugins_loaded', 'remove_variable_product_add_to_cart', 1);

Why is this not working, and what am I doing wrong?

Upvotes: 0

Views: 1297

Answers (1)

Hamid Reza Yazdani
Hamid Reza Yazdani

Reputation: 564

You can not change the plugins_loaded hook from the theme, because this hook has already been executed before running the theme.

There are two ways to remove this hook:

  1. Develop a plugin and install it and put the code inside it.

  2. Go to the following path: RECOMMENDED

public_html/wp-content/mu-plugins/

And create an index.php file and put your code in it.

NOTE

mu_plugins means Must Use Plugin. WordPress first executes its core files, then files inside the mu_plugins and plugins directory, and finally the theme. If you do not have the mu_plugins folder in the wp-content directory, create one and create your file inside it.

Upvotes: 1

Related Questions