Renderer

Handles rendering of product filters and filtered product loops.

This class is a wrapper around WP_Query responsible for managing the display configuration and rendering of WooCommerce product filters and their associated product loops. It handles settings like number of columns, product limits, specific product IDs, and CSS classes for the product display.

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

$query  : WP_Query
The WP_Query instance for handling product queries.
$shortcode_attributes  : array<string|int, mixed>
Shortcode attributes for customizing the product display.
$wc_query  : WC_Query
The WC_Query instance for accessing filtering logic.
$wcf_query  : Query|null
The WCF Query instance for accessing filter query logic.
__construct()  : mixed
Constructor - set default values from WooCommerce settings
convert_attributes_to_string()  : string
Convert an array of attributes to a shortcode attributes string
create_wc_product_query()  : WP_Query
Create a properly configured WooCommerce product query.
get_query()  : WP_Query
Get the WP_Query instance
get_shortcode_attribute()  : mixed
Get a specific shortcode attribute value.
get_wc_query()  : WC_Query
Get the WC_Query instance
get_wcf_query()  : Query|null
Get the WCF Query instance.
refresh_query_conditions()  : void
Refresh query conditions to pick up any changes
render()  : string
Render the products using our configured query
render_no_products_notice()  : string
Display a "no products found" notice using WooCommerce's notice system
set_product_ids()  : void
Set specific product IDs to render
set_shortcode_attributes()  : self
Set shortcode attributes for customizing the product display.
set_wcf_query()  : self
Set the WCF Query instance for the renderer.
apply_product_selection()  : void
Apply product selection based on IDs or SKUs.
apply_taxonomy_context_to_query()  : void
Apply current taxonomy context to the query if we're on a taxonomy page.
apply_taxonomy_filters()  : void
Apply taxonomy filters from shortcode attributes.
apply_wc_product_query_logic()  : void
Apply the same logic as WC_Query::product_query()
get_ordering_args()  : array<string|int, mixed>
Get ordering arguments based on shortcode attributes, WooCommerce defaults or WCF Query order_by.
get_posts_per_page()  : int
Get the number of posts per page based on shortcode attributes.
get_products()  : array<string|int, mixed>
Get the products using our configured query
render_products()  : string
Render products using WooCommerce's standard template system
sanitize_shortcode_attributes()  : array<string|int, mixed>
Sanitize and validate shortcode attributes.
setup_query()  : void
Setup the product query with the same conditions as the main shop query

Properties

$query

The WP_Query instance for handling product queries.

private WP_Query $query

$shortcode_attributes

Shortcode attributes for customizing the product display.

private array<string|int, mixed> $shortcode_attributes = []

Array of shortcode attributes.

$wc_query

The WC_Query instance for accessing filtering logic.

private WC_Query $wc_query

$wcf_query

The WCF Query instance for accessing filter query logic.

private Query|null $wcf_query = null

Methods

__construct()

Constructor - set default values from WooCommerce settings

public __construct() : mixed
Return values
mixed

convert_attributes_to_string()

Convert an array of attributes to a shortcode attributes string

public static convert_attributes_to_string(array<string|int, mixed> $attributes) : string
Parameters
$attributes : array<string|int, mixed>

Array of attribute key-value pairs

Return values
string

Formatted shortcode attributes

create_wc_product_query()

Create a properly configured WooCommerce product query.

public static create_wc_product_query() : WP_Query

This is a static utility method that can be used by other classes.

Return values
WP_Query

A properly configured WooCommerce product query.

get_query()

Get the WP_Query instance

public get_query() : WP_Query
Return values
WP_Query

get_shortcode_attribute()

Get a specific shortcode attribute value.

public get_shortcode_attribute(string $key[, mixed $default = null ]) : mixed
Parameters
$key : string

The attribute key.

$default : mixed = null

The default value if key doesn't exist.

Return values
mixed

The attribute value or default.

get_wc_query()

Get the WC_Query instance

public get_wc_query() : WC_Query
Return values
WC_Query

get_wcf_query()

Get the WCF Query instance.

public get_wcf_query() : Query|null
Return values
Query|null

The WCF Query instance or null if not set.

refresh_query_conditions()

Refresh query conditions to pick up any changes

public refresh_query_conditions() : void
Return values
void

render()

Render the products using our configured query

public render() : string
Return values
string

HTML output

render_no_products_notice()

Display a "no products found" notice using WooCommerce's notice system

public static render_no_products_notice([string $message = '' ]) : string
Parameters
$message : string = ''

Optional custom message to display

Return values
string

HTML output of the notice

set_product_ids()

Set specific product IDs to render

public set_product_ids(array<string|int, mixed> $product_ids) : void
Parameters
$product_ids : array<string|int, mixed>

Array of product IDs to render

Return values
void

set_shortcode_attributes()

Set shortcode attributes for customizing the product display.

public set_shortcode_attributes(array<string|int, mixed> $attributes) : self
Parameters
$attributes : array<string|int, mixed>

Array of shortcode attributes.

Return values
self

set_wcf_query()

Set the WCF Query instance for the renderer.

public set_wcf_query(Query $wcf_query) : self
Parameters
$wcf_query : Query

The WCF Query instance.

Return values
self

apply_product_selection()

Apply product selection based on IDs or SKUs.

private apply_product_selection() : void
Return values
void

apply_taxonomy_context_to_query()

Apply current taxonomy context to the query if we're on a taxonomy page.

private static apply_taxonomy_context_to_query(WP_Query $query) : void
Parameters
$query : WP_Query

The query to modify.

Return values
void

apply_taxonomy_filters()

Apply taxonomy filters from shortcode attributes.

private apply_taxonomy_filters() : void
Return values
void

apply_wc_product_query_logic()

Apply the same logic as WC_Query::product_query()

private apply_wc_product_query_logic() : void
Return values
void

get_ordering_args()

Get ordering arguments based on shortcode attributes, WooCommerce defaults or WCF Query order_by.

private get_ordering_args() : array<string|int, mixed>
Return values
array<string|int, mixed>

Ordering arguments.

get_posts_per_page()

Get the number of posts per page based on shortcode attributes.

private get_posts_per_page() : int
Return values
int

Number of posts per page.

get_products()

Get the products using our configured query

private get_products() : array<string|int, mixed>
Return values
array<string|int, mixed>

Array of WC_Product objects

render_products()

Render products using WooCommerce's standard template system

private render_products(array<string|int, mixed> $products) : string
Parameters
$products : array<string|int, mixed>

Array of WC_Product objects

Return values
string

HTML output

sanitize_shortcode_attributes()

Sanitize and validate shortcode attributes.

private sanitize_shortcode_attributes(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Raw shortcode attributes.

Return values
array<string|int, mixed>

Sanitized attributes.

setup_query()

Setup the product query with the same conditions as the main shop query

private setup_query() : void
Return values
void

Search results