• Resolved DesignLoud

    (@designloud)


    Hey all, I need some help here if anyone is able to chime in and offer their support. So I want to create a plugin that will offer a dropdown on the catalog page of Woocommerce so that users can select how many products are being viewed per page. I almost (in my eyes) have it but cant quite work out the kinks. Any takers?

    Here is what I have:

    function woocommerce_sortby_page() {
    
    	if ('woocommerce_catalog_page_ordering'==$twelve)
      {
      add_filter('loop_shop_per_page', create_function('$cols', 'return 12;'));
      }
    elseif ('woocommerce_catalog_page_ordering'==$sixteen)
      {
      add_filter('loop_shop_per_page', create_function('$cols', 'return 16;'));
      }
      elseif ('woocommerce_catalog_page_ordering'==$twenty)
      {
      add_filter('loop_shop_per_page', create_function('$cols', 'return 20;'));
      }
      elseif ('woocommerce_catalog_page_ordering'==$twentyfour)
      {
      add_filter('loop_shop_per_page', create_function('$cols', 'return 24;'));
      }
      elseif ('woocommerce_catalog_page_ordering'==$twentyeight)
      {
      add_filter('loop_shop_per_page', create_function('$cols', 'return 28;'));
      }
    else
      {
      add_filter('loop_shop_per_page', create_function('$cols', 'return 4;'));;
      }
    }
    
    function woocommerce_catalog_page_ordering() {
    ?>
    <form action="<?php woocommerce_sortby_page ?>">
    <select name="woocommerce-sort-by-columns">
    <option value="<?php $twelve ?>">12</option>
    <option value="<?php $sixteen ?>">16</option>
    <option value="<?php $twenty ?>" selected>20</option>
    <option value="<?php $twentyfour ?>">24</option>
    <option value="<?php $twentyeight ?>">28</option>
    </select>
    </form>
    <?php
    }
    
    add_action( 'woocommerce_pagination', 'woocommerce_catalog_page_ordering', 20 );

    I’m sure I am probably way off but am new to plugins and relatively new to the codex and PHP..

    Here is how Woo does their “Show results per page” which I assume would be similar to what I need to do?

    <form class="woocommerce_ordering" method="POST">
    	<select name="sort" class="orderby">
    		<?php
    			$catalog_orderby = apply_filters('woocommerce_catalog_orderby', array(
    				'menu_order' 	=> __('Default sorting', 'woocommerce'),
    				'title' 		=> __('Sort alphabetically', 'woocommerce'),
    				'date' 			=> __('Sort by most recent', 'woocommerce'),
    				'price' 		=> __('Sort by price', 'woocommerce')
    			));
    
    			foreach ( $catalog_orderby as $id => $name )
    				echo '<option value="' . $id . '" ' . selected( $_SESSION['orderby'], $id, false ) . '>' . $name . '</option>';
    		?>
    	</select>
    </form>

    Thanks for the help and Happy Holidays!

Viewing 4 replies - 16 through 19 (of 19 total)
  • It is working!

    No idea why. I didn’t change anything but it just fixed itself!

    Hi Luke

    I was using woocommerce 1.6.6 when I submitted the code. The pagination has had a overhaul in woocommerce 2.0. Are you using woocommerce’s built-in pagination or the theme’s pagination and have you got the newest version of the proffet theme.

    I’m using flexishop 2 and i’m upgrading to woocommerce 2.0 this weeks so I will try and resolve this on my test site in the next few days as I will need this functionality when I upgrade the plugin for my client.

    Thread Starter DesignLoud

    (@designloud)

    Hey Luke, I dont know who’s version you were using but if it was our version found here then all you should need to do is replace the “your-web-address.com” with your actual web address.. Version should not matter since we are writing our own functions and hooking in to Woocommerce, which has and I anticipate it remaining the same in future updates.

    Hope this helps, thanks

    Thanks for getting back to me. It seems to be working now. Great work by the way!

    Luke

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘Trying to create plugin for results per page – Woocommerce’ is closed to new replies.