本篇文章更新時間:2021/04/08
如有資訊過時或語誤之處,歡迎使用 Contact 功能通知。
一介資男的 LINE 社群開站囉!歡迎入群聊聊~
如果本站內容對你有幫助,歡迎使用 BFX Pay 加密貨幣 或 新台幣 贊助支持。
顧客、消費者在 WooCommerce 結帳的時候其實有很多客製化的機會。像是之前筆記過的可以參考 WooCommerce 標籤。
互動這件事分主動與被動,主動是指顧客點擊畫面上的物件,預期會有怎樣的反應發生,而被動就是操作的過程中,系統因為條件滿足而觸發一些反應。
通常被動的部分就能讓顧客感受加分,不然遇到不理解操作設計時,很難去說是設計的爛還是客戶的笨了是吧(?)
結帳時能夠讓程式端取得一些顧客的資料要仰靠 WooCommerce Fragments 片段互動,參考這篇筆記: [WooCommerce] 片段(fragments)互動程式設計要點
可以簡單地說這樣的互動,會讓後端程式可以拿到多一點使用者結帳前的資訊,進而來判斷,像是:是不是老客戶?買的多寡要不要給折扣?運費邏輯的計算符合銷售成本?... 等
拿到顧客的資訊方法如下:(WooCommerce v2.1 以後適用)
//結帳付款人欄位
$billing = WC()->customer->get_billing();
$billing_first_name = WC()->customer->get_billing_first_name();
$billing_last_name = WC()->customer->get_billing_last_name();
$billing_company = WC()->customer->get_billing_company();
$billing_address = WC()->customer->get_billing_address();
$billing_address_1 = WC()->customer->get_billing_address_1();
$billing_address_2 = WC()->customer->get_billing_address_2();
$billing_city = WC()->customer->get_billing_city();
$billing_state = WC()->customer->get_billing_state();
$billing_postcode = WC()->customer->get_billing_postcode();
$billing_country = WC()->customer->get_billing_country();
//運送收貨端欄位
$shipping = WC()->customer->get_shipping();
$shipping_first_name = WC()->customer->get_shipping_first_name();
$shipping_last_name = WC()->customer->get_shipping_last_name();
$shipping_company = WC()->customer->get_shipping_company();
$shipping_address = WC()->customer->get_shipping_address();
$shipping_address_1 = WC()->customer->get_shipping_address_1();
$shipping_address_2 = WC()->customer->get_shipping_address_2();
$shipping_city = WC()->customer->get_shipping_city();
$shipping_state = WC()->customer->get_shipping_state();
$shipping_postcode = WC()->customer->get_shipping_postcode();
$shipping_country = WC()->customer->get_shipping_country();
Ref: WooCommerce set billing and shipping information
除了這些內建方法外,有自己資料想從前端透過片段功能同步後端的話還可以透過 Session 功能的 set
& get
來存取,例如: WC()->session->set('變數名稱','變數值')
與
WC()->session->get('變數名稱')
。
-
取得顧客當下選擇的物流方法
WC()->session->get('chosen_shipping_methods')
[WooCommerce] 程式取得當下消費者選擇運送方法的應用 -
取得顧客當下選擇的金流方法
WC()->session->get('chosen_payment_method')
[WooCommerce] 程式開發時判斷建立訂單的時機
後記
這標題我也不知道日後找筆記時找不找得到,但有筆記一下應該會有感覺吧XD