Linz Darlington
Linz Darlington

Reputation: 671

remove_action not working for functions within a plugin

I'm trying to use remove_action to prevent a part of a plugin from running - don't ask me why :-).

The function within the plugin is:

add_action( 'woocommerce_before_single_product_summary', array( $this, 'show_product_gallery' ), 30 );

and I'm trying to remove it by:

remove_action( 'woocommerce_before_single_product_summary', array( $this, 'show_product_gallery' ), 30 );

For some reason it isn't doing the trick, although this usually works in Wordpress / WooCommerce.

Can anyone shine a light on why this might be please? I have also tried hooking my function to other things e.g.

add_action( 'init', 'remove_it' );
function remove_it() {
remove_action( 'woocommerce_before_single_product_summary', array( $this, 'show_product_gallery' ), 30 );
}

(Plugin Code: https://codedump.io/share/axGWwMwAH0vn/1/linzs-hook-not-working) Cheers,

Linz

Edited: This question is different to the previous one about remove_action not working, because that was related to the wrong priority - whereas this priority is correct at 30.

Upvotes: 1

Views: 1568

Answers (1)

Joe Beans
Joe Beans

Reputation: 294

You need to access the class variable globally. Please try this.

add_action( 'wp', 'remove_it' );
function remove_it() {
 global $WC_Product_Gallery_slider;
 remove_action( 'woocommerce_before_single_product_summary', array( $WC_Product_Gallery_slider, 'show_product_gallery' ), 30 );
}

Upvotes: 1

Related Questions