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

woocommerce - custom shop page sorting e pagination WordPress

  • SOLVED

Hi, I have some problems with woocommerce customization:


1 ) - custom page sorting

I did a custom shop page, to have this loop

showposts=9&post_type=product&meta_key=_sale_price&meta_value=0&meta_compare=>

at this link http://www.kickproduction.it/gsmart/offerte/

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: http://www.kickproduction.it/gsmart/offerte/
Default Shop Page: http://www.kickproduction.it/gsmart/negozio/

3 ) - Default Shop page sorting by meta value

at this page: http://www.kickproduction.it/gsmart/negozio/

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)

2012-12-06

Kyle answers:

For #2 on the http://www.kickproduction.it/gsmart/offerte/ 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: http://www.cleancode.co.nz/blog/713/jquery-noconflict-wordpress


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.


2012-12-06

Dbranes answers:

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

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type='text/javascript' src='http://www.kickproduction.it/gsmart/wp-includes/js/jquery/jquery.js?ver=1.7'></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="http://wordpress.org/extend/plugins/infinite-scroll/"]]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() )
return;


in line 114 here:

http://plugins.svn.wordpress.org/infinite-scroll/trunk/infinite-scroll.php

ps:

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';
break;
case 'title':
$orderby = 'post_title';
$meta_key = '_sale_price';
break;
case 'date':
$orderby = 'post_date';
$meta_key = '_sale_price';
break;
case 'price':
$orderby = 'post_date';
$meta_key = '_sale_price';
break;
case 'scad_asc':
$orderby = 'meta_value_num';
$meta_key = '_sale_price_dates_to';
break;
default:
break;
}
$query='post_type=product&meta_key='.$metakey.'&meta_value=0&meta_compare=>'.'&paged='.$paged.'&order=ASC&orderby='.$orderby;
$wp_query->query($query);


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 http://snipt.org/xGac1

This is custom shop page "page-offerte.php" http://snipt.org/xGae7

2012-12-06

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...

2012-12-06

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 http://snipt.org/xGac1

This is custom shop page "page-offerte.php" http://snipt.org/xGae7





Arnav Joy comments:

in page-offerte.php try changing

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

to


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

2012-12-07

e4chess answers:

Manlio,


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'] = '';
break;
case 'price_desc' :
$args['orderby'] = 'meta_value_num';
$args['order'] = 'desc';
$args['meta_key'] = '_price';
break;
case 'title_desc' :
$args['orderby'] = 'title';
$args['order'] = 'desc';
$args['meta_key'] = '';
break;
endswitch;
}
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. ||