Advertisement
Guest User

Untitled

a guest
May 1st, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1. // Lets create the function to house our form
  2.     function woocommerce_catalog_page_ordering() {
  3.         // change default number of products per page
  4.     add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 12;' ), 20 );
  5.     ?>
  6.             <form action="" method="POST" name="results" class="store-perpage">
  7.                     <span class="font-perpage">Show</span> <select name="woocommerce-sort-by-columns" id="woocommerce-sort-by-columns" class="sortby" onchange="document.forms['results'].submit();">
  8.                     <?php
  9.      
  10.             //  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.
  11.                 $shopCatalog_orderby = apply_filters('woocommerce_sortby_page', array(
  12.                                     ''        => __('',  'woocommerce'),
  13.                     '12'      => __('12',  'woocommerce'),
  14.                     '20'      => __('20',  'woocommerce'),
  15.                     '32'      => __('32',  'woocommerce'),
  16.                     '48'      => __('48',  'woocommerce'),
  17.                                     '-1'      => __('all', 'woocommerce'),
  18.                 ));
  19.      
  20.                 foreach ( $shopCatalog_orderby as $sort_id => $sort_name )
  21.                     echo '<option value="' . $sort_id . '" ' . selected( $_SESSION['sortby'], $sort_id, false ) . ' >' . $sort_name . '</option>';
  22.             ?>
  23.                     </select>
  24.             <span class="font-perpage">Item('s) Per Page!</span>
  25.             </form>
  26.     <?php
  27.      
  28.     }
  29.      
  30.     // now we set our cookie if we need to
  31.     function dl_sort_by_page($count) {
  32.       if (isset($_COOKIE['shop_pageResults'])) { // if normal page load with cookie
  33.          $count = $_COOKIE['shop_pageResults'];
  34.       }
  35.       if (isset($_POST['woocommerce-sort-by-columns'])) { //if form submitted
  36.         setcookie('shop_pageResults', $_POST['woocommerce-sort-by-columns'], time()+1209600, '/', 'itestwebpageshere.biz', false); //this will fail if any part of page has been output- hope this works!
  37.         $count = $_POST['woocommerce-sort-by-columns'];
  38.       }
  39.       // else normal page load and no cookie
  40.       return $count;
  41.     }
  42.      
  43.     add_filter('loop_shop_per_page','dl_sort_by_page');
  44.     add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_page_ordering', 20 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement