Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // Lets create the function to house our form
  2. function woocommerce_catalog_page_ordering() {
  3. ?>
  4. <form action="" method="POST" name="results">
  5. <select name="woocommerce-sort-by-columns" id="woocommerce-sort-by-columns" class="sortby" onchange="this.form.submit()">
  6. <?php
  7.  
  8.         //  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.
  9.             $shopCatalog_orderby = apply_filters('woocommerce_sortby_page', array(
  10.                 ''       => __('Results per page', 'woocommerce'),
  11.                 '24'    => __('24 per page', 'woocommerce'),
  12.                 '36'        => __('36 per page', 'woocommerce'),
  13.                 '48'        => __('48 per page', 'woocommerce'),
  14.                 '64'        => __('64 per page', 'woocommerce'),
  15.             ));
  16.  
  17.             foreach ( $shopCatalog_orderby as $sort_id => $sort_name )
  18.                 echo '<option value="' . $sort_id . '" ' . selected( $_SESSION['sortby'], $sort_id, false ) . ' >' . $sort_name . '</option>';
  19.         ?>
  20. </select>
  21.  
  22. </form>
  23. <?php
  24.  
  25. }
  26.  
  27. // now we set our cookie if we need to
  28. function dl_sort_by_page($count) {
  29.   if (isset($_COOKIE['shop_pageResults'])) { // if normal page load with cookie
  30.      $count = $_COOKIE['shop_pageResults'];
  31.   }
  32.   if (isset($_POST['woocommerce-sort-by-columns'])) { //if form submitted
  33.     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!
  34.     $count = $_POST['woocommerce-sort-by-columns'];
  35.   }
  36.   // else normal page load and no cookie
  37.   return $count;
  38. }
  39.  
  40. add_filter('loop_shop_per_page','dl_sort_by_page');
  41. add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_page_ordering', 20 );