Ask your WordPress questions! Pay money and get answers fast! (more info)

woocommerce - custom shop page sorting e pagination WordPress


Hi, I have some problems with woocommerce customization:

1 ) - custom page sorting

I did a custom shop page, to have this loop


at this link

The loop works, but the Sorting option doesn't.

2 ) - custom page infinite scroll

I have the plugin Infinite-Scroll, in default shop page works, in my custom shop page doesn't

Custom Shop Page:
Default Shop Page:

3 ) - Default Shop page sorting by meta value

at this page:

I added the option sort by "In scadenza" that returns product with meta key "_sale_price_to" order "ASC"

It works but, as you can see, the products with the meta key "_sale_price_to" is after the other products without meta key "_sale_price_to".

..and I want first product whit meta key and then products without meta key

anyone could help me ?

Answers (5)


Kyle answers:

For #2 on the you are getting a console error that is saying "Uncaught ReferenceError: infinite_scroll is not defined " check to see if you can resolve that by looking over any custom code you added on that page to make sure there are no errors or conflict. No conflict js wrappers may help too.

Manlio Ma comments:

Yes, I see the consol error and i just checked that both pages have same code, How I can make No conflict to the page ?

Kyle comments:

Do you have any javascript on the page?

Here is a brief explanation:

Manlio Ma comments:

I didn't write Js on this page, I have Js in the header and is the same that other page and the infinite scroll is a plugin, I just activeted it.


Dbranes answers:

Hi, it looks like you are loading jquery twice, first v1.8.3 and then v1.7.2,

<script src=""></script>
<script type='text/javascript' src=''></script>

Manlio Ma comments:

If I erase one of this cose the Tooltips and toggle doesn't works.
But I repeat, the wordpress plugin [[LINK href=""]]Infinite-Scroll[[/LINK]]
in thie HOMEpage works perfectly !

Dbranes comments:

maybe code line this is stopping the script from loading on your other pages:

function enqueue_js() {
//no need to show on singular pages
if ( is_singular() )

in line 114 here:


Singular page is when any of the following return true: is_single(), is_page() or is_attachment().

Manlio Ma comments:

Thanx Dbranes, I canched the line 114 and now works... Any suggestion for other problems ?

Dbranes comments:

you might try and play with something like this (for part 1):

(just an untested idea)

$sort = $_REQUEST['sort'] ? $_REQUEST['sort'] : 'default';
switch ( strtolower($sort) ) {
case 'menu_order':
$orderby = 'menu_order';
$meta_key = '_sale_price';
case 'title':
$orderby = 'post_title';
$meta_key = '_sale_price';
case 'date':
$orderby = 'post_date';
$meta_key = '_sale_price';
case 'price':
$orderby = 'post_date';
$meta_key = '_sale_price';
case 'scad_asc':
$orderby = 'meta_value_num';
$meta_key = '_sale_price_dates_to';

Manlio Ma comments:

Sorry, when I have to put this code ?

I have added this code to function.php to have "in Scadenza" sorting option

This is custom shop page "page-offerte.php"


John Cotton answers:

The "Uncaught ReferenceError: infinite_scroll is not defined" appears to be because you've got no infinitescroll.js plugin.

I had quick look through your included js and none of it features an infinite_scroll plugin...

I'd start with that...


Arnav Joy answers:

for the first and the third problem , can you provide your code which you have used?

Manlio Ma comments:

I have added this code to function.php to have "in Scadenza" sorting option

This is custom shop page "page-offerte.php"

Arnav Joy comments:

in page-offerte.php try changing



$wp_query->query(array('post_type' => 'product' ,'meta_key ' => '_sale_price' , 'meta_value' => '0' , 'meta_compare' => '>' ,'paged' => $paged));


e4chess answers:


1 & 3. ) Custom sorting options ACS / DESC --

* This code should be added to functions.php of your theme
add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args');

function custom_woocommerce_get_catalog_ordering_args( $args ) {
if (isset($_SESSION['orderby'])) {
switch ($_SESSION['orderby']) :
case 'date_asc' :
$args['orderby'] = 'date';
$args['order'] = 'asc';
$args['meta_key'] = '';
case 'price_desc' :
$args['orderby'] = 'meta_value_num';
$args['order'] = 'desc';
$args['meta_key'] = '_price';
case 'title_desc' :
$args['orderby'] = 'title';
$args['order'] = 'desc';
$args['meta_key'] = '';
return $args;

add_filter('woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby');

function custom_woocommerce_catalog_orderby( $sortby ) {
$sortby['title_desc'] = 'Reverse-Alphabetically';
$sortby['price_desc'] = 'Price (highest to lowest)';
$sortby['date_asc'] = 'Oldest to newest';
return $sortby;

2 .) To fix infinite scrolling issue - First disable the WP- infinite-scroll plugin & delete (it will increase site speed:). Then add this function to your WP-Content Themes/(YourTheme Name)/function.php folder. Inside the function.php folder you can place this code snippet below to manual edit how many products you want displayed throughout site. This can go @ the very end of function.php

// Display 24 products per page. Goes in functions.php
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );

||if you would like to change the amount of items displayed just edit the # 24 to whatever # you prefer. ||