我正在尝试将“增值税”字段添加到“客户帐单地址”,而这在“结帐”页面上使用以下代码:
// Company Name Required
add_filter('woocommerce_checkout_fields','custom_override_checkout_fields');
function custom_override_checkout_fields($fields){
$fields['billing']['billing_company']['required'] = true;
$fields['billing']['billing_vat'] = array(
'label' => __('VAT Number','woocommerce'),
'placeholder' => _x('Enter VAT Number','placeholder','woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields;
}
//Display field value on the order edit page
add_action('woocommerce_admin_order_data_after_shipping_address','my_custom_checkout_field_display_admin_order_meta',10,1);
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('VAT Number').':</strong> ' . get_post_meta($order->id,'_billing_vat',true) . '</p>';
}
//Order the fields
add_filter("woocommerce_checkout_fields","order_fields");
function order_fields($fields){
$order = array(
"billing_first_name",
"billing_last_name",
"billing_company",
"billing_vat",
"billing_country",
"billing_city",
"billing_postcode",
"billing_state",
"billing_address_1",
"billing_address_2",
"billing_email",
"billing_phone",
);
foreach($order as $field){$ordered_fields[$field] = $fields["billing"][$field];}
$fields["billing"] = $ordered_fields;
return $fields;
}
我还要求在帐户选项中的客户帐单地址上设置它 . 因为我需要将其链接到注册页面,因为我希望用户注册所有凭据,包括他们为B2B Webstore拥有的增值税号 .
有没有人知道或者有没有人能指出我如何执行这项任务,不仅要在结帐页面上显示增值税号码的结算字段,还要在用户 Profiles 页面上显示,以及如何添加所有这些字段在注册页面?
在此情况下,提前感谢您的任何帮助!
1 回答
嗯,这很简单 . 你的代码应该是这样的:
您可以根据需要添加更多自定义字段 .
是的,您可以使用
woocommerce_billing_fields
过滤器挂钩在my-account/edit-address/billing/
下添加自定义字段 .所以这个代码应该如下所示: