Skip to content

Instantly share code, notes, and snippets.

@kloon
Created January 23, 2013 10:23
Show Gist options
  • Select an option

  • Save kloon/4604097 to your computer and use it in GitHub Desktop.

Select an option

Save kloon/4604097 to your computer and use it in GitHub Desktop.
WooCommerce Custom Orderby
<?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;
}
?>
@bentasm1
Copy link
Copy Markdown

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