我不需要在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' );
已将其从结算中删除,但我无法通过任何方式将其从发货中删除。有关通用地删除所有电话号码要求的任何帮助,或有关过滤/取消设置以删除帐户页面上的送货号码的提示的提示?谢谢!
答案 0 :(得分:2)
以下是在帐户和结帐页(两个页面)中完成此操作的完整方式:
// 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中,默认情况下,发送电子邮件和电话字段并不存在