Hook type: filter
Filters the number of product columns the plugin applies to the shop and product archive pages. This filter is used when applying the plugin’s own annasta Filters > Product lists > Shop columns setting, and its support may vary depending on your current theme. Use it to further customize the columns set up of your product lists.
Parameters
(int)$columns — the value of the plugin’s annasta Filters > Product lists > Shop columns setting (0 if not set).
Return
int — the number of columns. Return 0 to keep the theme’s or WooCommerce’s columns unchanged.
Note: 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:
- the plugin’s product categories list, as a
columns-{n}CSS class - page loads, through WooCommerce’s
loop_shop_columnsfilter - AJAX filtering, as the
columnsattribute of the products shortcode
Examples
add_filter( 'awf_set_shop_columns', function( $columns ) {
if( wp_is_mobile() ) {
$columns = 2;
}
return $columns;
} );
The following example applies the theme’s setting only when the plugin’s own annasta Filters > Product lists > Shop columns setting is empty. The check also leaves alone any value an earlier callback has already set, for example from another plugin or the bundled theme support. The callback only fills in a value when nothing else has.:
add_filter( 'awf_set_shop_columns', function( $columns ) {
if( empty( $columns ) ) {
$columns = (int) get_theme_mod( 'my_theme_shop_columns', 0 );
}
return $columns;
} );
In the above example my_theme_shop_columns stands for your theme’s own columns option. If the theme has no value set either, the callback returns 0 and WooCommerce’s default columns stay in place.
