在Woocommerce我试图使结帐地址字段不需要下面的代码...但我有this error“请输入一个地址继续”,当提交结帐表格。
我的代码设置地址结帐字段不需要:
add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1
);
function wc_npr_filter_phone( $address_fields ) {
$address_fields['billing_phone']['required'] = true;
$address_fields['billing_country']['required'] = false;
$address_fields['billing_last_name']['required'] = false;
$address_fields['billing_city']['required'] = false;
$address_fields['billing_postcode']['required'] = false;
$address_fields['billing_email']['required'] = false;
$address_fields['billing_state']['required'] = false;
$address_fields['billing_address_1']['required'] = false;
$address_fields['billing_address_2']['required'] = false;
return $address_fields;
}
//make shipping fields not required in checkout
add_filter( 'woocommerce_shipping_fields',
'wc_npr_filter_shipping_fields', 10, 1 );
function wc_npr_filter_shipping_fields( $address_fields ) {
$address_fields['shipping_first_name']['required'] = false;
$address_fields['shipping_last_name']['required'] = false;
$address_fields['shipping_address_1']['required'] = false;
$address_fields['shipping_address_2']['required'] = false;
$address_fields['shipping_city']['required'] = false;
$address_fields['shipping_country']['required'] = false;
$address_fields['shipping_postcode']['required'] = false;
$address_fields['shipping_state']['required'] = false;
return $address_fields;
}
HTML似乎也不错:
如何在WooCommerce中不需要结帐地址字段?
3条答案
按热度按时间zsohkypk1#
您应该需要使用
woocommerce_default_address_fields
过滤器钩子,而不是解释here。替换代码:
由于计费邮箱和电话已经默认为必填,如果您希望不需要,则需要增加此代码:
所有的代码都在你的活动子主题(或活动主题)的functions.php文件中。测试和作品。
dz6r00yl2#
唯一对我有帮助的是为国家添加了一个字段,并使其不可见(因为我不需要它)
uqcuzwp83#
这种方法使用'woocommerce_checkout_fields',当我在自己的网站上测试时,这是我可以将billing_phone字段更改为必填字段的唯一方法。
https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/