1
votes

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.

1
I have also tried to use the 'plugins_loaded' hook instead of init, but to no avail. codex.wordpress.org/Plugin_API/Action_Reference/plugins_loaded - Linz Darlington
Have you tried increasing/decreasing the priority of the remove_action? Not sure if that will work, but might be worth a shot. - michaelrmcneill
Thanks for the spot, Dan. I did actually check out that post before I posted mine, but none of the suggestions worked. I'm using the correct priority (30) and I have tried hooking to to 'plugins_loaded'. Have you got any others ideas? - Linz Darlington
Thanks michaelmcneill. I'll give it a go, but as i understand it the remove action needs to share the same priority as the add action, in this case '30'. - Linz Darlington

1 Answers

1
votes

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 );
}