I wrote a simple plugin that performs some logic on thumbnails in WooCommerce. This plugin worked great for about a year, until the client switched to a new theme. Now the plugin is no longer working and I’ve narrowed the problem to remove_action()
failing.
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
if (! remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10) ) {
echo 'FAILED to remove action<br/>';
}
/**
* WooCommerce Loop Product Thumbs
**/
if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {
function woocommerce_template_loop_product_thumbnail() {
echo woocommerce_get_product_thumbnail();
}
}
I don’t know if this is because of the order plugins are loaded, or if I’m making the call incorrectly due to a change in WooCommerce. I’ve read some topics that indicate the remove_action()
should follow my custom add_action()
so I reversed the order accordingly. It doesn’t work either way – remove_action()
is always returning FALSE.
I’ve been banging my head against a wall all day trying to figure this out. Can anyone give me a clue on a sure-fire way to execute the remove, or a way to debug it?
Thanks.
Try changing the priority flag of [add/remove]_action() to something higher, like 90.
It’s a little hard to guess without seeing what the theme is actually doing!