簡體   English   中英

從Woocommerce中的賬單/運輸領域中刪除手機?

[英]Remove phone from billing/shipping fields everywhere in Woocommerce?

我不需要在woocommerce中收集客戶電話號碼,因此我使用以下代碼將其從結帳流程中刪除:

add_filter( 'woocommerce_checkout_fields', 'pbj_woocommerce_checkout_fields' );
function pbj_woocommerce_checkout_fields( $fields ) {
  unset($fields['billing']['billing_phone']);
  unset($fields['shipping']['shipping_phone']);
$fields['billing']['billing_email']['class'] = array('form-row-wide');
return $fields;}

(抱歉可怕的代碼粘貼,第一次!)

這在結帳頁面上效果很好,但一旦進入“我的帳戶”區域,用戶仍然需要在他們編輯帳單或送貨地址時添加電話號碼。 我添加了這段代碼:

function pbj_remove_billingphone($fields) {
unset( $fields ['billing_phone'] );
return $fields;}
add_filter( 'woocommerce_billing_fields', 'pbj_remove_billingphone' );

已將其從結算中刪除,但我無法通過任何工作將其從發貨中刪除。 有關通用地刪除所有電話號碼要求的任何幫助,或有關過濾/取消設置以刪除帳戶頁面上的送貨號碼的提示的提示? 謝謝!

以下是在帳戶和結帳頁面兩個頁面)中完成此操作的完整方法:

// Remove billing phone (and set email field class to wide)
add_filter( 'woocommerce_billing_fields', 'remove_billing_phone_field', 20, 1 );
function remove_billing_phone_field($fields) {
    $fields ['billing_phone']['required'] = false; // To be sure "NOT required"

    $fields['billing_email']['class'] = array('form-row-wide'); // Make the field wide

    unset( $fields ['billing_phone'] ); // Remove billing phone field
    return $fields;
}

// Remove shipping phone (optional)
add_filter( 'woocommerce_shipping_fields', 'remove_shipping_phone_field', 20, 1 );
function remove_shipping_phone_field($fields) {
    $fields ['shipping_phone']['required'] = false; // To be sure "NOT required"

    unset( $fields ['shipping_phone'] ); // Remove shipping phone field
    return $fields;
}

代碼位於活動子主題(或活動主題)的function.php文件中。 經過測試和工作

通常,WooCommmerce中默認不存在發送電子郵件和電話字段

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM