add custom columns to order list view
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Orders {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_filter( 'manage_edit-shop_order_columns', array(__CLASS__, 'add_additional_columns_to_orders_screen') );
|
||||
|
||||
add_action( 'manage_shop_order_posts_custom_column', array(__CLASS__, 'add_custom_columns_content') );
|
||||
}
|
||||
|
||||
public static function add_additional_columns_to_orders_screen( $columns ){
|
||||
|
||||
$new_columns = array();
|
||||
|
||||
$new_columns['reference'] = 'Location';
|
||||
$new_columns['commercial_lead'] = 'Commercial lead';
|
||||
$new_columns['customer'] = 'Customer';
|
||||
|
||||
$insertAfterColumn = 1;
|
||||
|
||||
return array_merge(array_slice($columns,0,$insertAfterColumn+1), $new_columns, array_slice($columns,$insertAfterColumn+1));
|
||||
|
||||
}
|
||||
|
||||
public static function add_custom_columns_content( $column ){
|
||||
|
||||
global $post;
|
||||
$column_content = '';
|
||||
|
||||
switch ($column){
|
||||
case 'reference':
|
||||
$column_content = Wiaas_Order::get_order_reference($post->ID);
|
||||
break;
|
||||
|
||||
case 'commercial_lead':
|
||||
$column_content = Wiaas_Order::get_order_commercial_lead_name($post->ID);
|
||||
break;
|
||||
|
||||
case 'customer':
|
||||
$column_content = Wiaas_Order::get_order_customer_full_name($post->ID);
|
||||
break;
|
||||
}
|
||||
|
||||
echo $column_content;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Admin_Orders::init();
|
||||
@@ -30,7 +30,9 @@ class Wiaas_Admin {
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-user-profile.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-countries.php';
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-countries.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-orders.php';
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
}
|
||||
|
||||
@@ -370,6 +370,25 @@ class Wiaas_Order {
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function get_order_customer_full_name($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$customer_user_id = $order->get_customer_id();
|
||||
|
||||
$customer = get_userdata($customer_user_id);
|
||||
|
||||
return $customer->last_name . ' ' . $customer->first_name;
|
||||
}
|
||||
|
||||
public static function get_order_commercial_lead_name($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$commercial_lead_org_id = $order->get_meta('_wiaas_commercial_lead_id', true);
|
||||
$commercial_lead_organization_info = wiaas_get_organization_info($commercial_lead_org_id);
|
||||
|
||||
return $commercial_lead_organization_info['name'];
|
||||
}
|
||||
|
||||
public static function set_order_vat($order_id, $vat_code) {
|
||||
add_post_meta($order_id, '_wiaas_vat_code', $vat_code);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user