WooCommerce Code Reference

Search results

WC_Template_Loader

Template loader class.

Table of Contents

$shop_page_id Store the shop page ID. int
$in_content_filter Store whether we're processing a product inside the_content filter. bool
$theme_support Is WooCommerce support defined? bool
init() Hook in methods. mixed
template_loader() Load a template. string
get_template_loader_default_file() Get the default filename for a template. string
get_template_loader_files() Get an array of filenames to search for a given template. string[]
comments_template_loader() Load comments template. string
unsupported_theme_init() Hook in methods to enhance the unsupported theme experience on pages. mixed
unsupported_theme_shop_page_init() Hook in methods to enhance the unsupported theme experience on the Shop page. mixed
unsupported_theme_product_page_init() Hook in methods to enhance the unsupported theme experience on Product pages. 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. mixed
unsupported_archive_layered_nav_compatibility() Add layered nav args to WP_Query args generated by the 'products' shortcode. array
force_single_template_filter() Force the loading of one of the single templates instead of whatever template was about to be loaded. string
get_current_shop_view_args() Get information about the current shop page view. array
unsupported_theme_title_filter() Filter the title and insert WooCommerce content on the shop page. string
unsupported_theme_shop_content_filter() Filter the content and insert WooCommerce content on the shop page. string
unsupported_theme_product_content_filter() Filter the content and insert WooCommerce content on the shop page. string
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. string
in_content_filter() Are we filtering content for unsupported themes? bool
unsupported_theme_single_featured_image_filter() Prevent the main featured image on product pages because there will be another featured image in the gallery. string
unsupported_theme_remove_review_tab() Remove the Review tab and just use the regular comment form. array

Properties

$in_content_filter

Store whether we're processing a product inside the_content filter.

private static bool $in_content_filter = \false

Methods

template_loader()

Load a template.

public static template_loader( $template : string ) : 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

get_template_loader_default_file()

Get the default filename for a template.

private static get_template_loader_default_file( ) : string
Tags
since
Return values
string

get_template_loader_files()

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

private static get_template_loader_files( $default_file : string ) : string[]
Parameters
$default_file : string

The default file name.

Tags
since
Return values
string[]

comments_template_loader()

Load comments template.

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

template to load.

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
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
Return values
mixed

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
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
Return values
mixed

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( $query : array ) : array
Parameters
$query : array

WP_Query args.

Tags
since
Return values
array

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( $template : string ) : string
Parameters
$template : string

Path to template.

Tags
since
Return values
string

get_current_shop_view_args()

Get information about the current shop page view.

private static get_current_shop_view_args( ) : array
Tags
since
Return values
array

unsupported_theme_title_filter()

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

public static unsupported_theme_title_filter( $title : string , $id : int ) : 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
Return values
string

unsupported_theme_shop_content_filter()

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

public static unsupported_theme_shop_content_filter( $content : string ) : 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
Return values
string

unsupported_theme_product_content_filter()

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

public static unsupported_theme_product_content_filter( $content : string ) : 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
Return values
string

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( $comments_number : string ) : string
Parameters
$comments_number : string

The comments number text.

Tags
since
Return values
string

in_content_filter()

Are we filtering content for unsupported themes?

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

unsupported_theme_single_featured_image_filter()

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( $html : string ) : string
Parameters
$html : string

Img element HTML.

Tags
since
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( $tabs : array ) : array
Parameters
$tabs : array

Tab info.

Return values
array
Back to the top