Created
January 23, 2013 10:23
-
-
Save kloon/4604097 to your computer and use it in GitHub Desktop.
WooCommerce Custom Orderby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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 'sku_asc' : | |
$args['orderby'] = 'meta_value'; | |
$args['order'] = 'asc'; | |
$args['meta_key'] = '_sku'; | |
break; | |
} | |
} | |
return $args; | |
} | |
add_filter('woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby'); | |
function custom_woocommerce_catalog_orderby( $sortby ) { | |
$sortby['sku_asc'] = 'SKU'; | |
return $sortby; | |
} | |
?> |
alias: it goes in your themes functions.php. Google "theme functions.php" and you'll see walkthroughs of how to paste code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good morning, thanks for the input, I'm new to this and am learning, my question is if this code snippet is used to sort the products in my shop WooCommerce according sku, and if so what should I do? Where shall I put it? Thank you very much in advance and sorry for my English.