loop_shop_per_page
Filters the number of products shown per page in a product loop.
In WC_Query::product_query() this applies only when the query does not already set posts_per_page. Other callers, such as the Product Collection block, apply it unconditionally.
Usage
add_filter( 'loop_shop_per_page', 'wp_kama_loop_shop_per_page_filter' );
/**
* Function for `loop_shop_per_page` filter-hook.
*
* @param int $per_page Products per page.
*
* @return int
*/
function wp_kama_loop_shop_per_page_filter( $per_page ){
// filter...
return $per_page;
}
- $per_page(int)
- Products per page.
Default: store's columns times its rows setting
Changelog
| Since 1.0.0 | Introduced. |
Where the hook is called
loop_shop_per_page
loop_shop_per_page
woocommerce/includes/class-wc-query.php 595
$q->set( 'posts_per_page', $q->get( 'posts_per_page' ) ? $q->get( 'posts_per_page' ) : apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ) );
woocommerce/src/Blocks/BlockTypes/ProductQuery.php 144
$this->asset_data_registry->add( 'loopShopPerPage', apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ) );
woocommerce/src/Blocks/BlockTypes/ProductCollection/Controller.php 224
$this->asset_data_registry->add( 'loopShopPerPage', apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ) );