How to Force Avada to Use WooCommerce Thumbnail Function

Uncategorized WooCommerce WordPress

WooCommerce & Avada

The problem with a lot of “multipurpose” themes is that when they override the default behaviors of WordPress or one of its plugins, they forget to re-introduce the filters that were there before they did their thing.

Avada does this mistake with the woocommerce_product_get_image filter, a very important filter that is the only one you can use if you want to customize the WooCommerce product image in the shop or single product page. Many plugins rely on that filter. Here are a few based on a quick Github search:

  • SG Optimizer
  • WooCommerce Ajax Filters
  • WooCommerce Follow Up Emails
  • LearnPress – WooCommerce Payment Methods Integration
  • Badge Management for WooCommerce

These plugins and plugin that relies on the woocommerce_product_get_image filter hook will not work with Avada unless the hook is restored.

Restoring the woocommerce_product_get_image Filter Hook

After a bit of digging in Avada source code, I’ve found that the theme removes the default WooCommerce thumbnail function in the Avada_Wocommerce class with this code:

    add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'thumbnail' ], 10 );
    remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );

The effect of this code has to be reverted, i.e., we need to restore the default WooCommerce behavior and remove Avada’s. Here is the code for that:

/**
 * Restore the `woocommerce_product_get_image` filter hook removed by Avada.
 */
add_action( 'woocommerce_init', function() {
	global $avada_woocommerce;
	remove_action( 'woocommerce_before_shop_loop_item_title', [ $avada_woocommerce, 'thumbnail' ], 10 );
	add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
}, PHP_INT_MAX );

Just add this code to your theme functions.php file or using the Code Snippets plugin and your WooCommerce shop and archive pages will work with the plugins as they should.

Leave a Reply

Your email address will not be published. Required fields are marked *