add_filter( 'loop_shop_per_page', static function() {
return $posts_per_page;
}, 19 );
function cr_products_paged () {
$selected_1 = '';
$selected_2 = '';
$selected_3 = 'selected';
$selected_4 = '';
$posts_per_page = 20;
if ( isset( $_GET['posts_per_page'] ) ) {
$count_to_show = sanitize_text_field( $_GET['posts_per_page'] );
switch ( $count_to_show ) {
case '5':
$posts_per_page = 5;
$selected_1 = 'selected';
$selected_2 = '';
$selected_3 = '';
$selected_4 = '';
break;
case '10':
$posts_per_page = 10;
$selected_1 = '';
$selected_2 = 'selected';
$selected_3 = '';
$selected_4 = '';
break;
case '20':
$posts_per_page = 20;
$selected_1 = '';
$selected_2 = '';
$selected_3 = 'selected';
$selected_4 = '';
break;
case '30':
$posts_per_page = 30;
$selected_1 = '';
$selected_2 = '';
$selected_3 = '';
$selected_4 = 'selected';
break;
}
}
?>
<div class="product-count-to-show">
<span>Показать: </span>
<form method="get" class="cr-product-paged">
<select name="posts_per_page" size="1" onchange="this.form.submit()">
<option value="5" <?php echo $selected_1 ?>>5</option>
<option value="10" <?php echo $selected_2 ?>>10</option>
<option value="20" <?php echo $selected_3 ?>>20</option>
<option value="30" <?php echo $selected_4 ?>>30</option>
</select>
<?php wc_query_string_form_fields( null, array( 'posts_per_page', 'paged', 'submit', 'product-page' ) ); ?>
</form>
</div>
<?php
add_filter( 'loop_shop_per_page', static function() {
return $posts_per_page;
}, 19 );
}
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 10;' ), 19 );
function cr_products_paged () {
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 1;' ), 19 );
}