Created
August 9, 2015 15:26
-
-
Save freelancedaddytv/2ac15ad594b9cae715a0 to your computer and use it in GitHub Desktop.
WooCommerce ShortCode Sort by Price
This file contains hidden or 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
/* 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