使用外掛
派工單外掛 : CRM WordPress Plugin – RepairBuddy 使用付費版
匯出外掛 : WP Import Export Lite 使用免費版
程式編輯外掛 : Code Snippets 使用免費版
匯出外掛 邏輯設定與欄位名稱
Status / doesn’t equal / trash
_order_id 派工單ID
Title 案件編號
Date 建立日期
__order_id 派工單ID
Title 案件編號
Date 建立日期
_customer_label 客戶名稱
Dispatcher 派單人員
_technician 接單人員 (PHP:add_technican_label) - 用於抓取接單人員01
_order_id 接單人員 (PHP:add_technican_label) - 用於抓取接單人員02
_delivery_date 預定出貨日期
_wc_order_status_label 工單狀態
_wc_payment_status_label 付款狀態
_wc_order_note 工單備註
_case_detail 派工單紀錄(文字)
Image URL 派工單紀錄(圖片)
Attachment URL 派工單紀錄(檔案)
Post Modified Date 最後修改日期
_order_id 總金額

接單人員設定01 – 要額外設定抓取接單人員
由於匯出外掛抓不到接單人員的名稱,只能抓到接單人員的ID
所以需要設定程式來抓取資料
要是之後有新增新的派單人員,程式也需要更改掛抓不到接單人員的名稱,只能抓到接單人員的ID
所以需要設定程式來抓取資料,要是之後有新增新的派單人員,程式也需要更改
要設定這麼麻煩主要是我不知道該怎麼抓取CRM裡面變數的值
才只好這樣設定,未來有優化空間
使用Code Snippets來設定,程式如下
function add_technican_label( $value ) {
if($value == 9){
$tech_name = "陳詔宣";
}
else if($value == 10){
$tech_name = "許森媁";
}
else if($value == 11){
$tech_name = "何欣樺";
}
else if($value == 12){
$tech_name = "李梓晴";
}
else if($value == 14){
$tech_name = "台北小蟬";
}
else if($value == 15){
$tech_name = "台中芃宣";
}
else if($value == 21){
$tech_name = "奇虹代工";
}
return $tech_name." ID:(".$value.")";
}


接單人員設定02 – 自動抓取接單人員 (正在使用)
第一種方法抓不到資料的原因是我使用的變數不對
在WP Import Export Lite我使用 _technician
_technician是可以抓到接單人員的id沒錯,可是我要的是接單人員的文字名稱
使用 _order_id 這個欄位,這才是文章id的值
這樣就能透過文章id抓取接單人員的文字資料
一樣使用Code Snippets來設定,程式如下
//取得接單人員姓名
function add_technican_label( $order_id ) {
$technician = get_post_meta($order_id, "_technician", true);
$tech_user = get_user_by('id', $technician);
$tech_name = $tech_user->first_name . ' ' . $tech_user->last_name;
return $tech_name." ID:(".$order_id.")";
}


匯出成果

取得派工單金額
設定方法同接單人員,設定代碼如下
只要於Code Snippets輸入代碼,並使用WP Import Export Lite設定_order_id抓取PHP function匯出即可
//取得派工單總金額
function add_crm_price( $order_id ) {
$system_currency = get_option('wc_system_currency');
$crm_total_price = $system_currency.wc_order_grand_total($order_id, "grand_total");
return $crm_total_price;
}


