Hook type: filter
Filters the default number of products per page that the plugin applies to the shop and product archive pages. Use it to take the value from your theme’s own settings, or to change it by device or page.
The plugin reads this filter on init (priority 20), so add your callback in functions.php or on init with a lower priority. A value above 0 applies to:
- page loads, through WooCommerce’s
loop_shop_per_pagefilter - AJAX filtering, as the
limitattribute of the products shortcode - the “Products per page” control, as its default value (a visitor’s selection in the “Products per page” control always takes priority over this default).
Note on AJAX filtering: when the value is 0, AJAX results show the number of columns × WooCommerce’s default rows per page. If your theme sets products per page in its own options, set the value using the annasta Filters > Product lists > Products per page setting or customize it using this filter. Otherwise AJAX results can show a different number of products than the first page load.
Parameters
(int)$ppp — the value of the plugin’s annasta Filters > Product lists > Products per page setting.
Return
int — the number of products per page. Return 0 to keep the theme’s or WooCommerce’s value unchanged.
Example
add_filter( 'awf_set_ppp_default', function( $ppp ) {
if( empty( $ppp ) ) {
$ppp = (int) get_theme_mod( 'my_theme_products_per_page', 0 );
}
return $ppp;
} );
In the above example my_theme_products_per_page stands for your theme’s own option. The empty() check keeps the value entered in the plugin settings. If the theme has no value either, the callback returns 0.
