WooCommerce Code Reference

WC_Template_Loader
in package

Template loader class.

Table of Contents

$in_content_filter  : bool
Store whether we're processing a product inside the_content filter.
$shop_page_id  : int
Store the shop page ID.
$theme_support  : bool
Is WooCommerce support defined?
comments_template_loader()  : string
Load comments template.
force_single_template_filter()  : string
Force the loading of one of the single templates instead of whatever template was about to be loaded.
in_content_filter()  : bool
Are we filtering content for unsupported themes?
init()  : mixed
Hook in methods.
template_loader()  : string
Load a template.
unsupported_archive_layered_nav_compatibility()  : array<string|int, mixed>
Add layered nav args to WP_Query args generated by the 'products' shortcode.
unsupported_theme_comments_number_filter()  : string
Suppress the comments number on the Shop page for unsupported themes since there is no commenting on the Shop page.
unsupported_theme_init()  : mixed
Hook in methods to enhance the unsupported theme experience on pages.
unsupported_theme_product_content_filter()  : string
Filter the content and insert WooCommerce content on the shop page.
unsupported_theme_remove_review_tab()  : array<string|int, mixed>
Remove the Review tab and just use the regular comment form.
unsupported_theme_shop_content_filter()  : string
Filter the content and insert WooCommerce content on the shop page.
unsupported_theme_single_featured_image_filter()  : string
Prevent the main featured image on product pages because there will be another featured image in the gallery.
unsupported_theme_title_filter()  : string
Filter the title and insert WooCommerce content on the shop page.
add_support_for_product_page_gallery()  : mixed
Add theme support for Product page gallery.
get_current_shop_view_args()  : array<string|int, mixed>
Get information about the current shop page view.
get_template_loader_default_file()  : string
Get the default filename for a template except if a block template with the same name exists.
get_template_loader_files()  : array<string|int, string>
Get an array of filenames to search for a given template.
has_block_template()  : bool
Checks whether a block template with that name exists.
taxonomy_has_block_template()  : bool
Checks whether a block template for a given taxonomy exists.
unsupported_theme_product_page_init()  : mixed
Hook in methods to enhance the unsupported theme experience on Product pages.
unsupported_theme_shop_page_init()  : mixed
Hook in methods to enhance the unsupported theme experience on the Shop page.
unsupported_theme_tax_archive_init()  : mixed
Enhance the unsupported theme experience on Product Category and Attribute pages by rendering those pages using the single template and shortcode-based content. To do this we make a dummy post and set a shortcode as the post content. This approach is adapted from bbPress.

Properties

Methods

comments_template_loader()

Load comments template.

public static comments_template_loader(string $template) : string
Parameters
$template : string

template to load.

Return values
string

force_single_template_filter()

Force the loading of one of the single templates instead of whatever template was about to be loaded.

public static force_single_template_filter(string $template) : string
Parameters
$template : string

Path to template.

Tags
since
3.3.0
Return values
string

in_content_filter()

Are we filtering content for unsupported themes?

public static in_content_filter() : bool
Tags
since
3.3.2
Return values
bool

template_loader()

Load a template.

public static template_loader(string $template) : string

Handles template usage so that we can use our own templates instead of the theme's.

Templates are in the 'templates' folder. WooCommerce looks for theme overrides in /theme/woocommerce/ by default.

For beginners, it also looks for a woocommerce.php template first. If the user adds this to the theme (containing a woocommerce() inside) this will be used for all WooCommerce templates.

Parameters
$template : string

Template to load.

Return values
string

unsupported_archive_layered_nav_compatibility()

Add layered nav args to WP_Query args generated by the 'products' shortcode.

public static unsupported_archive_layered_nav_compatibility(array<string|int, mixed> $query) : array<string|int, mixed>
Parameters
$query : array<string|int, mixed>

WP_Query args.

Tags
since
3.3.4
Return values
array<string|int, mixed>

unsupported_theme_comments_number_filter()

Suppress the comments number on the Shop page for unsupported themes since there is no commenting on the Shop page.

public static unsupported_theme_comments_number_filter(string $comments_number) : string
Parameters
$comments_number : string

The comments number text.

Tags
since
3.4.5
Return values
string

unsupported_theme_init()

Hook in methods to enhance the unsupported theme experience on pages.

public static unsupported_theme_init() : mixed
Tags
since
3.3.0
Return values
mixed

unsupported_theme_product_content_filter()

Filter the content and insert WooCommerce content on the shop page.

public static unsupported_theme_product_content_filter(string $content) : string

For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.

Parameters
$content : string

Existing post content.

Tags
since
3.3.0
Return values
string

unsupported_theme_remove_review_tab()

Remove the Review tab and just use the regular comment form.

public static unsupported_theme_remove_review_tab(array<string|int, mixed> $tabs) : array<string|int, mixed>
Parameters
$tabs : array<string|int, mixed>

Tab info.

Return values
array<string|int, mixed>

unsupported_theme_shop_content_filter()

Filter the content and insert WooCommerce content on the shop page.

public static unsupported_theme_shop_content_filter(string $content) : string

For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.

Parameters
$content : string

Existing post content.

Tags
since
3.3.0
Return values
string

Prevent the main featured image on product pages because there will be another featured image in the gallery.

public static unsupported_theme_single_featured_image_filter(string $html) : string
Parameters
$html : string

Img element HTML.

Tags
since
3.3.0
Return values
string

unsupported_theme_title_filter()

Filter the title and insert WooCommerce content on the shop page.

public static unsupported_theme_title_filter(string $title, int $id) : string

For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.

Parameters
$title : string

Existing title.

$id : int

ID of the post being filtered.

Tags
since
3.3.0
Return values
string

Add theme support for Product page gallery.

private static add_support_for_product_page_gallery() : mixed
Tags
since

x.x.x

Return values
mixed

get_current_shop_view_args()

Get information about the current shop page view.

private static get_current_shop_view_args() : array<string|int, mixed>
Tags
since
3.3.0
Return values
array<string|int, mixed>

get_template_loader_default_file()

Get the default filename for a template except if a block template with the same name exists.

private static get_template_loader_default_file() : string
Tags
since
3.0.0
since
5.5.0

If a block template with the same name exists, return an empty string.

since
6.3.0

It checks custom product taxonomies

Return values
string

get_template_loader_files()

Get an array of filenames to search for a given template.

private static get_template_loader_files(string $default_file) : array<string|int, string>
Parameters
$default_file : string

The default file name.

Tags
since
3.0.0
Return values
array<string|int, string>

has_block_template()

Checks whether a block template with that name exists.

private static has_block_template(string $template_name) : bool

**Note: ** This checks both the templates and block-templates directories as both conventions should be supported.

Parameters
$template_name : string

Template to check.

Tags
since
5.5.0
Return values
bool

taxonomy_has_block_template()

Checks whether a block template for a given taxonomy exists.

private static taxonomy_has_block_template(object $taxonomy) : bool

Note: This checks both the templates and block-templates directories as both conventions should be supported.

Parameters
$taxonomy : object

Object taxonomy to check.

Return values
bool

unsupported_theme_product_page_init()

Hook in methods to enhance the unsupported theme experience on Product pages.

private static unsupported_theme_product_page_init() : mixed
Tags
since
3.3.0
Return values
mixed

unsupported_theme_shop_page_init()

Hook in methods to enhance the unsupported theme experience on the Shop page.

private static unsupported_theme_shop_page_init() : mixed
Tags
since
3.3.0
Return values
mixed

unsupported_theme_tax_archive_init()

Enhance the unsupported theme experience on Product Category and Attribute pages by rendering those pages using the single template and shortcode-based content. To do this we make a dummy post and set a shortcode as the post content. This approach is adapted from bbPress.

private static unsupported_theme_tax_archive_init() : mixed
Tags
since
3.3.0
Return values
mixed