Support » Plugins and Hacks » Products per page selector

Products per page selector

  • Hi, I setup a “disaplay number of products per page” drop down selector using code from this very helpful chap – http://designloud.com/how-to-add-products-per-page-dropdown-to-woocommerce/?showmodaldialog=1#comment-1554

    The trouble is, it has stopped my pagination working. Selecting the next page results in a 404 not found error.

    Any ideas what is going wrong?

    Here is the code.


    // Lets create the function to house our form
    function woocommerce_catalog_page_ordering() {
    <form action="" method="POST" name="results">
    <select name="woocommerce-sort-by-columns" id="woocommerce-sort-by-columns" class="sortby" onchange="this.form.submit()">
            //  This is where you can change the amounts per page that the user will use  feel free to change the numbers and text as you want, in my case we had 4 products per row so I chose to have multiples of four for the user to select.
                $shopCatalog_orderby = apply_filters('woocommerce_sortby_page', array(
                    ''       => __('Results per page', 'woocommerce'),
                    '24'    => __('24 per page', 'woocommerce'),
                    '36'        => __('36 per page', 'woocommerce'),
                    '48'        => __('48 per page', 'woocommerce'),
                    '64'        => __('64 per page', 'woocommerce'),
                foreach ( $shopCatalog_orderby as $sort_id => $sort_name )
                    echo '<option value="' . $sort_id . '" ' . selected( $_SESSION['sortby'], $sort_id, false ) . ' >' . $sort_name . '</option>';
    // now we set our cookie if we need to
    function dl_sort_by_page($count) {
      if (isset($_COOKIE['shop_pageResults'])) { // if normal page load with cookie
         $count = $_COOKIE['shop_pageResults'];
      if (isset($_POST['woocommerce-sort-by-columns'])) { //if form submitted
        setcookie('shop_pageResults', $_POST['woocommerce-sort-by-columns'], time()+1209600, '/', 'your-web-address.com', false); //this will fail if any part of page has been output- hope this works!
        $count = $_POST['woocommerce-sort-by-columns'];
      // else normal page load and no cookie
      return $count;
    add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_page_ordering', 20 );


  • The topic ‘Products per page selector’ is closed to new replies.