Created
June 14, 2019 16:52
-
-
Save nczz/c1e891664e31f70686986a046ec1bfff to your computer and use it in GitHub Desktop.
用 WC_Session 紀錄結帳欄位資料與 WooCommerce 片段程式互動設計
This file contains 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 | |
function save_data_before_open_new_page($value) { | |
$data = $_POST['post_data']; | |
parse_str(html_entity_decode($data), $pdata); | |
if (isset($pdata['billing_first_name']) && $pdata['billing_first_name'] != "") { | |
WC()->session->set('billing_first_name', $pdata['billing_first_name']); | |
} | |
if (isset($pdata['billing_phone']) && $pdata['billing_phone'] != "") { | |
WC()->session->set('billing_phone', $pdata['billing_phone']); | |
} | |
if (isset($pdata['billing_company']) && $pdata['billing_company'] != "") { | |
WC()->session->set('billing_company', $pdata['billing_company']); | |
} | |
if (isset($pdata['billing_email']) && $pdata['billing_email'] != "") { | |
WC()->session->set('billing_email', $pdata['billing_email']); | |
} | |
$value['#billing_first_name'] = '<input type="text" class="input-text " name="billing_first_name" id="billing_first_name" placeholder="請填入最多中文5個字或英文10個字" value="' . WC()->session->get('billing_first_name') . '" autocomplete="given-name" autofocus="autofocus">'; | |
$value['#billing_phone'] = '<input type="tel" class="input-text " name="billing_phone" id="billing_phone" placeholder="手機號碼格式為:0912345678" value="' . WC()->session->get('billing_phone') . '" autocomplete="tel">'; | |
$value['#billing_company'] = '<input type="text" class="input-text " name="billing_company" id="billing_company" placeholder="" value="' . WC()->session->get('billing_company') . '" autocomplete="organization">'; | |
$value['#billing_email'] = '<input type="email" class="input-text " name="billing_email" id="billing_email" placeholder="" value="' . WC()->session->get('billing_email') . '" autocomplete="email">'; | |
return $value; | |
} | |
add_filter('woocommerce_update_order_review_fragments', 'save_data_before_open_new_page', 10, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment