若希望 WooCommerce 結帳頁時,不要出現那麼多欄位要訪客填寫,不仿利用下面的程式碼,將帳單地址 & 運送地址的欄位隱藏起來。
使用方式很簡單,只要在 WordPress 後臺,在外觀 > 佈景主題檔案編輯器 > 下拉選擇 functions.php 檔案 > 點擊選取:
<?php
// Add custom Theme Functions here
在上述文字下方插入以下程式碼即可。
add_filter( 'woocommerce_checkout_fields' , 'custom_remove_woo_checkout_fields' );
function custom_remove_woo_checkout_fields( $fields ) {
// 移除帳單地址欄位
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_phone']);
unset($fields['billing']['billing_email']);
// 移除運送地址欄位
unset($fields['shipping']['shipping_first_name']);
unset($fields['shipping']['shipping_last_name']);
unset($fields['shipping']['shipping_company']);
unset($fields['shipping']['shipping_address_1']);
unset($fields['shipping']['shipping_address_2']);
unset($fields['shipping']['shipping_city']);
unset($fields['shipping']['shipping_postcode']);
unset($fields['shipping']['shipping_country']);
unset($fields['shipping']['shipping_state']);
// 移除備註欄
unset($fields['order']['order_comments']);
return $fields;}