Skip to content

Instantly share code, notes, and snippets.

@freelancedaddytv
Created August 9, 2015 15:26
Show Gist options
  • Save freelancedaddytv/2ac15ad594b9cae715a0 to your computer and use it in GitHub Desktop.
Save freelancedaddytv/2ac15ad594b9cae715a0 to your computer and use it in GitHub Desktop.
WooCommerce ShortCode Sort by Price
/* Add this to functions.php */
add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_orderby' );
function woocommerce_shortcode_products_orderby( $args ) {
$standard_array = array('menu_order','title','date','rand','id');
if( isset( $args['orderby'] ) && !in_array( $args['orderby'], $standard_array ) ) {
$args['meta_key'] = '_price';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'asc'; /* Replace DESC or ASC for highest to lowest */
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment