WooCommerce Code Reference

WC_Widget_Top_Rated_Products extends WC_Widget
in package

Widget top rated products class.

Table of Contents

$settings  : array<string|int, mixed>
Settings.
$widget_cssclass  : string
CSS class.
$widget_description  : string
Widget description.
$widget_id  : string
Widget ID.
$widget_name  : string
Widget name.
__construct()  : mixed
Constructor.
cache_widget()  : string
Cache the widget.
flush_widget_cache()  : mixed
Flush the cache.
form()  : mixed
Outputs the settings update form.
get_cached_widget()  : bool
Get cached widget.
update()  : array<string|int, mixed>
Updates a particular instance of a widget.
widget()  : mixed
Output widget.
widget_end()  : mixed
Output the html at the end of a widget.
widget_start()  : mixed
Output the html at the start of a widget.
get_current_page_url()  : string
Get current page URL with various filtering props supported by WC.
get_instance_title()  : string
Get this widgets title.
get_widget_id_for_cache()  : string
Get widget id plus scheme/protocol to prevent serving mixed content from (persistently) cached widgets.
query_top_rated_products()  : WP_Query
Run the widget query, ordering through the product lookup table instead of the rating post meta.

Properties

Methods

cache_widget()

Cache the widget.

public cache_widget(array<string|int, mixed> $args, string $content) : string
Parameters
$args : array<string|int, mixed>

Arguments.

$content : string

Content.

Return values
string — the content that was cached

form()

Outputs the settings update form.

public form(array<string|int, mixed> $instance) : mixed
Parameters
$instance : array<string|int, mixed>

Instance.

Tags
see

WP_Widget->form

Return values
mixed —

get_cached_widget()

Get cached widget.

public get_cached_widget(array<string|int, mixed> $args) : bool
Parameters
$args : array<string|int, mixed>

Arguments.

Return values
bool — true if the widget is cached otherwise false

update()

Updates a particular instance of a widget.

public update(array<string|int, mixed> $new_instance, array<string|int, mixed> $old_instance) : array<string|int, mixed>
Parameters
$new_instance : array<string|int, mixed>

New instance.

$old_instance : array<string|int, mixed>

Old instance.

Tags
see

WP_Widget->update

Return values
array<string|int, mixed> —

widget()

Output widget.

public widget(array<string|int, mixed> $args, array<string|int, mixed> $instance) : mixed
Parameters
$args : array<string|int, mixed>

Arguments.

$instance : array<string|int, mixed>

Widget instance.

Tags
see
WP_Widget
Return values
mixed —

widget_end()

Output the html at the end of a widget.

public widget_end(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>

Arguments.

Return values
mixed —

widget_start()

Output the html at the start of a widget.

public widget_start(array<string|int, mixed> $args, array<string|int, mixed> $instance) : mixed
Parameters
$args : array<string|int, mixed>

Arguments.

$instance : array<string|int, mixed>

Instance.

Return values
mixed —

get_current_page_url()

Get current page URL with various filtering props supported by WC.

protected get_current_page_url() : string
Tags
since
3.3.0
Return values
string —

get_instance_title()

Get this widgets title.

protected get_instance_title(array<string|int, mixed> $instance) : string
Parameters
$instance : array<string|int, mixed>

Array of instance options.

Return values
string —

get_widget_id_for_cache()

Get widget id plus scheme/protocol to prevent serving mixed content from (persistently) cached widgets.

protected get_widget_id_for_cache(string $widget_id[, string $scheme = '' ]) : string
Parameters
$widget_id : string

Id of the cached widget.

$scheme : string = ''

Scheme for the widget id.

Tags
since
3.4.0
Return values
string — Widget id including scheme/protocol.

query_top_rated_products()

Run the widget query, ordering through the product lookup table instead of the rating post meta.

private query_top_rated_products(array<string|int, mixed> $query_args) : WP_Query

_wc_average_rating post meta is written for every product, so the meta join this replaces filters nothing out, while wc_product_meta_lookup holds one narrow row per product instead of one row per product in a table that grows with every extension's meta. Ordering is delegated to the same clause callback the shop catalog uses for "sort by average rating", which also breaks ties on rating count and product ID rather than leaving equally rated products in an undefined order.

The swap happens after woocommerce_top_rated_products_widget_args has run, and only when nothing on that filter changed the ordering arguments, so the filter payload keeps its documented shape and a consumer that overrides the ordering still wins.

Parameters
$query_args : array<string|int, mixed>

Query arguments, as returned by the widget args filter.

Return values
WP_Query —