从Woocommerce中的计费/发货字段中删除电话? [英] Remove phone from billing/shipping fields everywhere in Woocommerce?

查看:113
本文介绍了从Woocommerce中的计费/发货字段中删除电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不需要在woocommerce中收集客户电话号码,因此我使用以下代码从结帐流程中将其删除:

I don't need to collect customer phone numbers in woocommerce so I've used the following code to remove them from the checkout process:

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;}

(很抱歉,第一次粘贴丑陋的代码!)

(sorry for hideous code pasting, first time!)

在结帐页面上效果很好,但是一旦进入我的帐户区域,则用户在编辑帐单或送货地址时仍需要添加电话号码。我添加了以下代码:

That works great on the checkout page but once in the "my account" area, the user is still required to add a phone number if they edit their billing or shipping address. I have added this code:

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

已将其从结算中删除,但我无法采取任何措施将其从运输中删除。对普遍删除所有地方的电话号码要求的任何帮助,或者有关在帐户页面上过滤/取消删除送货电话号码的提示?谢谢!

which has removed it from billing, but I can't get anything to work to remove it from shipping. Any help on either something that universally removes the phone number requirement everywhere, or tips on what to filter/unset to remove the shipping phone number on the account page? Thank you!

推荐答案

这是在帐户和结帐页面(对于都是页面)

Here is the complete way to do it in account and checkout pages (for both pages):

// 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文件)。经过测试并可以正常工作

Code goes in function.php file of your active child theme (or active theme). Tested and works


在WooCommmerce中,默认情况下通常不包含电子邮件和电话字段

Normally shipping email and phone fields doesn't exist by default in WooCommmerce

这篇关于从Woocommerce中的计费/发货字段中删除电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆