Created
June 5, 2020 15:52
-
-
Save Musilda/6d8482354983ba5149733d5a544288bb to your computer and use it in GitHub Desktop.
This file contains 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 | |
add_filter( 'manage_edit-shop_order_sortable_columns', 'musilda_order_sortable_column' ); | |
function musilda_order_sortable_column( $columns ) { | |
$columns = array( 'order-weight' => 'order-weight' ); | |
return $columns; | |
} | |
add_filter( 'pre_get_posts', 'musilda_weight_order_query', 99 ); | |
function musilda_weight_order_query( $query ) { | |
global $pagenow; | |
if ( !is_admin() ){ | |
return $query; | |
} | |
if ( $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'shop_order' && (!isset( $_GET['orderby'] ) || empty( $_GET['orderby'] ) ) ) { | |
$query->set( 'orderby', 'ID' ); | |
$query->set( 'order', 'DESC' ); | |
} | |
$orderby = $query->get( 'orderby' ); | |
if ( 'order-weight' == $orderby ) { | |
$query->set( 'orderby', 'meta_value' ); | |
$query->set( 'meta_key', 'order-weigh' ); | |
$query->set( 'meta_query', [] ); | |
} | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment