Last active
December 17, 2015 07:48
-
-
Save asvechkar/5575106 to your computer and use it in GitHub Desktop.
Customize admin panel for custom types
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 | |
add_filter( 'manage_edit-orders_columns', 'admin_orders_header_columns', 10, 1); | |
add_action( 'manage_orders_posts_custom_column', 'admin_orders_data_row', 10, 2); | |
add_filter( 'manage_edit-orders_sortable_columns', 'admin_orders_sortable_columns' ); | |
function admin_orders_header_columns($columns) | |
{ | |
$columns = array( | |
'cb' => '<input type="checkbox" />', | |
'title' => __( 'Заказ' ), | |
'ordersum' => __( 'Сумма' ), | |
'author' => __( 'Клиент' ), | |
'orderstatus' => __( 'Статус' ), | |
'date' => __( 'Дата' ) | |
); | |
return $columns; | |
} | |
function admin_orders_data_row($column, $post_id) | |
{ | |
switch($column) | |
{ | |
case 'ordersum': | |
$ordersum = get_post_meta($post_id, 'wpcf-order_sum', true); | |
if ($ordersum) echo $ordersum; | |
break; | |
case 'orderstatus': | |
$order_status = ""; | |
$terms = get_the_terms(get_the_ID(), 'orderstatus'); | |
foreach($terms as $term) | |
{ | |
$order_status = $term->name; | |
} | |
echo $order_status; | |
break; | |
default: | |
break; | |
} | |
} | |
function admin_orders_sortable_columns( $columns ) { | |
$columns['ordersum'] = 'Сумма'; | |
$columns['orderstatus'] = 'Статус'; | |
return $columns; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment