Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aadityajs/8235880 to your computer and use it in GitHub Desktop.
Save aadityajs/8235880 to your computer and use it in GitHub Desktop.
WooCommerce - Change products per page conditionally
<?php
add_action( 'pre_get_posts', 'mj_change_per_page' );
function mj_change_per_page() {
if ( is_product_category( 'games' ) ) {
add_filter('loop_shop_per_page', create_function('$cols', 'return 1;') );
} else {
add_filter('loop_shop_per_page', create_function('$cols', 'return 8;') );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment