Woocommerce订单格式的帐单地址重新排序和自定义结算字段
问题描述:
感谢过滤器“WooCommerce管理帐单字段”我已通过电子邮件订购notificiación页脚中的帐单字段,但是当我尝试插入我的自定义结算字段没有出现。Woocommerce订单格式的帐单地址重新排序和自定义结算字段
add_filter('woocommerce_order_formatted_billing_address' , 'woo_reorder_billing_fields', 10, 2);
function woo_reorder_billing_fields($address, $wc_order) {
$address = array(
'first_name' => $wc_order->billing_first_name,
'last_name' => $wc_order->billing_last_name,
'company' => $wc_order->billing_company,
'my_field' => $wc_order->billing_my_field,
'country' => $wc_order->billing_country
);
return $address;
}
为了管理编辑,我可以告诉我的自定义计费领域得益于过滤器“woocommerce_admin_billing_fields”,先加入域,然后重新排序阵列。
我注意到我之前添加过,并且在结帐时使用过滤器“woocommerce_checkout_fields”重新排序了此字段。
如果“$ wc_order”对象在结帐中存储字段,为什么不显示我的自定义字段?
任何想法?
在此先感谢!
答
是,这里的解释:
我们将注册新cusotm领域,在这个例子中,场“增值税”来存储文档财政为公司在欧盟。有许多关于如何注册自定义字段并将其显示在管理员/用户面板中的文档。
add_filter('woocommerce_default_address_fields', 'woo_new_default_address_fields');
function woo_new_default_address_fields($fields) {
$fields['vat'] = array(
'label' => __('VAT number', 'woocommerce'),
'class' => array('form-row-wide', 'update_totals_on_change'),
);
$order = array(
"first_name",
"last_name",
"vat",
"company",
"country",
"address_1",
"address_2",
"city",
"state",
"postcode"
);
foreach($order as $field) {
$ordered_fields[$field] = $fields[$field];
}
$fields = $ordered_fields;
return $fields;
}
然后添加新的领域“增值税”仅计费领域的邮件注册,我们不希望它出现在地址的Fileds部分。
add_filter('woocommerce_order_formatted_billing_address' , 'woo_custom_order_formatted_billing_address', 10, 2);
function woo_custom_order_formatted_billing_address($address, $WC_Order) {
$address = array(
'first_name' => $WC_Order->billing_first_name,
'last_name' => $WC_Order->billing_last_name,
'vat' => $WC_Order->billing_vat,
'company' => $WC_Order->billing_company,
'address_1' => $WC_Order->billing_address_1,
'address_2' => $WC_Order->billing_address_2,
'city' => $WC_Order->billing_city,
'state' => $WC_Order->billing_state,
'postcode' => $WC_Order->billing_postcode,
'country' => $WC_Order->billing_country
);
return $address;
}
以下代码自定义地址的外观,这是我们必须将调用添加到新的VAT字段的位置。这使我们能够独立地为每个国家定制地址视图。
add_filter('woocommerce_formatted_address_replacements', function($replacements, $args){
$replacements['{vat}'] = $args['vat'];
return $replacements;
}, 10, 2);
add_filter('woocommerce_localisation_address_formats' , 'woo_includes_address_formats', 10, 1);
function woo_includes_address_formats($address_formats) {
$address_formats['ES'] = "{name}\n{company}\n{vat}\n{address_1}\n{address_2}\n{postcode} {city}\n{state}\n{country}";
$address_formats['default'] = "{name}\n{company}\n{vat}\n{nif}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode}\n{country}";
return $address_formats;
}
有任何问题要求提出!
我找到了解决方案,它在“class-wc-countries”中,用于格式化帐单地址。我很快写出解决方案 –
检查这个链接可能是你的问题解决方案:http://wordpress.stackexchange.com/questions/120347/woocommerce-add-custom-field-set-like-billing-fields –
@RonnieEsponja:how你解决了吗? – Sefran2