WC_Template_Loader::unsupported_theme_shop_content_filter
Filter the content and insert WooCommerce content on the shop page.
For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.
Method of the class: WC_Template_Loader{}
No Hooks.
Returns
String.
Usage
$result = WC_Template_Loader::unsupported_theme_shop_content_filter( $content );
- $content(string) (required)
- Existing post content.
Changelog
| Since 3.3.0 | Introduced. |
WC_Template_Loader::unsupported_theme_shop_content_filter() WC Template Loader::unsupported theme shop content filter code WC 10.6.2
public static function unsupported_theme_shop_content_filter( $content ) {
global $wp_query;
if ( self::$theme_support || ! is_main_query() || ! in_the_loop() ) {
return $content;
}
self::$in_content_filter = true;
// Remove the filter we're in to avoid nested calls.
remove_filter( 'the_content', array( __CLASS__, 'unsupported_theme_shop_content_filter' ) );
// Unsupported theme shop page.
if ( is_page( self::$shop_page_id ) ) {
$args = self::get_current_shop_view_args();
$shortcode = new WC_Shortcode_Products(
array_merge(
WC()->query->get_catalog_ordering_args(),
array(
'page' => $args->page,
'columns' => $args->columns,
'rows' => $args->rows,
'orderby' => '',
'order' => '',
'paginate' => true,
'cache' => false,
)
),
'products'
);
// Allow queries to run e.g. layered nav.
add_action( 'pre_get_posts', array( WC()->query, 'product_query' ) );
$content = $content . $shortcode->get_content();
// Remove actions and self to avoid nested calls.
remove_action( 'pre_get_posts', array( WC()->query, 'product_query' ) );
WC()->query->remove_ordering_args();
}
self::$in_content_filter = false;
return $content;
}