Elementor Pro – fixed `elementor-pro/modules/woocommerce/classes/base-products-renderer.php`

mgibbs189

{{gist file=”base-products-renderer.php” lang=”php”}}
<?php
namespace ElementorProModulesWoocommerceClasses;

if ( ! defined( ‘ABSPATH’ ) ) {
exit; // Exit if accessed directly
}

abstract class Base_Products_Renderer extends WC_Shortcode_Products {

public $query_results;

/**
* Override original `get_content` that returns an HTML wrapper even if no results found.
*
* @return string Products HTML
*/
public function get_content() {

// WooCommerce 4.0.0 and above
if ( function_exists( ‘WC’ ) && version_compare( WC()->version, ‘4.0.0’, ‘>=’ ) ) {
add_filter( ‘woocommerce_shortcode_products_query_results’, [ $this, ‘store_query_results’] );
$content = parent::get_content();
remove_filter( ‘woocommerce_shortcode_products_query_results’, [ $this, ‘store_query_results’] );

return $this->query_results->total ? $content : ”;
}

// WooCommerce < 4.0.0
$result = $this->get_query_results();

if ( empty( $result->total ) ) {
return ”;
}

return parent::get_content();
}

/**
* Prevent from running get_query_results() twice
*
* @return object Results data
*/
public function store_query_results( $results ) {
$this->query_results = $results;
return $results;
}
}

{{/gist}}