我正在尝试自定义WooCommerce结帐页面,如何编辑字段标签?
另外,如何从表单中删除2个字段?我不需要Company
和State
字段。
答案 0 :(得分:5)
我建议制作一个自定义插件来修改它,这样您就可以在以后轻松升级WooCommerce。
在自定义插件中,实现此处的一些代码:http://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-actions-and-filters/
例如,要删除公司和州:
// Hook in
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
// Our Hooked in function - $fields is passed via the filter
function custom_override_checkout_fields( $fields) {
unset($fields['shipping']['shipping_state']);
unset($fields['shipping']['shipping_company']);
return $fields;
}
如果您需要帮助制作插件,我就如何将自定义字段添加到“产品”页面提供了指导。我认为在这种情况下可能会有所帮助。 http://www.xatik.com/2013/02/06/add-custom-form-woocommerce-product/
答案 1 :(得分:1)
这是一个工作挂钩,需要添加到主题的functions.php文件中
add_filter( 'woocommerce_checkout_fields' , 'remove_checkout_fields' );
function remove_checkout_fields( $fields ) {
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_country']);
return $fields;
}
答案 2 :(得分:0)
为将来的读者更新-
WooCommerce文档现在在Customizing checkout fields using actions and filters上有一个法典文章,看起来很全面。
我要说的唯一一点是,从WooCommerce 3.5.1开始,使用Billing / Shipping_Address_2标签有一个小技巧,如我对this question的回答所述。