Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Created March 13, 2020 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgibbs189/29524fa5bb0bf438bd539a60ce12caec to your computer and use it in GitHub Desktop.
Save mgibbs189/29524fa5bb0bf438bd539a60ce12caec to your computer and use it in GitHub Desktop.
Elementor Pro - fixed `elementor-pro/modules/woocommerce/classes/base-products-renderer.php`
<?php
namespace ElementorPro\Modules\Woocommerce\Classes;
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment