I've got a list of user orders, with a custom field named "Delivery Date". This lets users pick a date when they want their order delivered. I am trying to make this custom field 'sortable' so the admin can sort orders by the delivery dates instead of the order date. This is the code I am using to display this custom meta field on the Orders page:
add_filter( 'manage_edit-shop_order_columns', 'bbloomer_add_new_order_admin_list_column' );
function bbloomer_add_new_order_admin_list_column( $columns ) {
$columns['delivery_date'] = 'Delivery Date';
return $columns;
}
and this is the code I am using to make this a 'sortable' column:
// Sort by custom column ==> changed (working)
add_filter( "manage_edit-shop_order_sortable_columns", 'custom_woo_admin_sort' );
function custom_woo_admin_sort( $columns )
{
$custom = array(
'delivery_date' => 'delivery_date',
);
return wp_parse_args( $custom, $columns );
}
Now it does make the column clickable, however it does not order the dates properly. It generates this url: edit.php?post_type=shop_order&wc-hide-notice=template_files&orderby=delivery_date&order=desc but the delivery dates still show up in the wrong order. Where am I going wrong here?
Photo for reference:
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742401199a4436945.html
评论列表(0条)