facetwp proposed update to elementor-pro/modules/woocommerce/classes/base-products-renderer.php

djrmom

{{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() {

add_filter( ‘woocommerce_shortcode_products_query_results’, [ $this, ‘grab_query_results’ ] );
$content = parent::get_content();
remove_filter( ‘woocommerce_shortcode_products_query_results’, [ $this, ‘grab_query_results’ ] );

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

/**
* Grab the shortcode pager data to prevent running $this->get_query_results() twice
*
* @return object Results data
*/
public function grab_query_results( $results ) {
$this->query_results = $results;
return $results;
}
}
{{/gist}}