wc_setup_loop()
Sets up the woocommerce_loop global from the passed args or from the main query.
No Hooks.
Return
null
. Nothing (null).
Usage
wc_setup_loop( $args );
- $args(array)
- Args to pass into the global.
Default: array()
Changelog
Since 3.3.0 | Introduced. |
wc_setup_loop() wc setup loop code WC 9.8.1
function wc_setup_loop( $args = array() ) { $default_args = array( 'loop' => 0, 'columns' => wc_get_default_products_per_row(), 'name' => '', 'is_shortcode' => false, 'is_paginated' => true, 'is_search' => false, 'is_filtered' => false, 'total' => 0, 'total_pages' => 0, 'per_page' => 0, 'current_page' => 1, ); // If this is a main WC query, use global args as defaults. if ( $GLOBALS['wp_query']->get( 'wc_query' ) ) { $default_args = array_merge( $default_args, array( 'is_search' => $GLOBALS['wp_query']->is_search(), 'is_filtered' => is_filtered(), 'total' => $GLOBALS['wp_query']->found_posts, 'total_pages' => $GLOBALS['wp_query']->max_num_pages, 'per_page' => $GLOBALS['wp_query']->get( 'posts_per_page' ), 'current_page' => max( 1, $GLOBALS['wp_query']->get( 'paged', 1 ) ), ) ); } // Merge any existing values. if ( isset( $GLOBALS['woocommerce_loop'] ) ) { $default_args = array_merge( $default_args, $GLOBALS['woocommerce_loop'] ); } $GLOBALS['woocommerce_loop'] = wp_parse_args( $args, $default_args ); }