Created
May 16, 2020 14:00
-
-
Save Musilda/e70d75b0e08c0d054415c2b8af9360d7 to your computer and use it in GitHub Desktop.
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
<?php | |
//Change sorting | |
add_filter( 'woocommerce_get_catalog_ordering_args', 'musilda_show_instock_products_first', 9999, 3 ); | |
function musilda_show_instock_products_first( $args, $orderby, $order ) { | |
if( $orderby == 'stock_status' ){ | |
$args['orderby'] = 'meta_value'; | |
$args['order'] = 'ASC'; | |
$args['meta_key'] = '_stock_status'; | |
} | |
return $args; | |
} | |
//Change default sorting | |
add_filter( 'woocommerce_default_catalog_orderby', 'musilda_default_stock_order' ); | |
function musilda_default_stock_order(){ | |
return array( 'stock_status', 'ASC' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment