I want to order products by specific meta key but I want to show all products including those ones which has not set this meta key. I want to show products with set meta key first and then the rest of the products.
Unfortunatelly this soluition woks only to show products whose has set that meta key:
add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args');
function custom_woocommerce_get_catalog_ordering_args( $args ) {
global $wp_query;
if (isset($_GET['orderby'])) {
switch ($_GET['orderby']) :
case 'myorder' :
$args['order'] = 'DESC';
$args['meta_key'] = 'myorder';
$args['orderby'] = 'meta_value_num';
break;
endswitch;
}
return $args;
}