[英]Hide checkout billing fields for customer user role in WooCommerce
[英]Hide WooCommerce billing and shipping fields in WordPress user profile
我找不到一种简单的方法来隐藏一些在 WordPress 后端的用户配置文件中可见的 WooCommerce 计费和运输字段。
例如,我想在 WordPress 用户配置文件中隐藏billing_address_2
和shipping_address_2
。 有没有用代码片段来做到这一点的好方法? 我尝试使用下面的代码在 css 中隐藏第六行,但我也无法让它工作。
#fieldset-billing.form-table tr:nth-child(6) {
display: none;
}
如何在 WordPress 用户配置文件中隐藏 WooCommerce 计费和运输字段?
用户配置文件屏幕中显示的计费和运输字段通过钩子woocommerce_customer_meta_fields
进行过滤。
要删除运输字段,您可以编写:
add_filter( 'woocommerce_customer_meta_fields', 'xbs_remove_shipping_fields' );
function xbs_remove_shipping_fields( $show_fields ) {
unset( $show_fields['shipping'] );
return $show_fields;
}
要删除所有字段,您可以返回一个空array
。
您可以将它添加到functions.php
文件中,然后取消设置它们,这样它们就不会被注册。
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
unset($fields['order']['billing_address_2']);
unset($fields['order']['shipping_address_2']);
return $fields;
}
从帐户页面中删除:
function custom_remove_checkout_fields($fields) {
unset($fields['order']['billing_address_2']);
unset($fields['order']['shipping_address_2']);
return $fields;
}
add_filter( 'woocommerce_default_address_fields', 'custom_remove_checkout_fields' );
如果它出现在另一个地方,你可以添加另一个钩子,但调用
add_filter( 'woocommerce_billing_fields', 'new_function_name' );
您可以在文件class-wc-countries.php
看到他们可用的其他钩子
有关更多信息和其他选项,您可以访问: https : //docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
要从 WordPress 后端用户配置文件中隐藏帐单和送货地址 2 字段,请尝试以下操作:
add_action('admin_head', 'custom_admin_user_styles');
function custom_admin_user_styles() {
?>
<style>
table#fieldset-billing tr:nth-child(5),
table#fieldset-shipping tr:nth-child(6){
display: none !important;
}
</style>';
<?php
}
代码位于活动子主题(或活动主题)的 function.php 文件中。 测试和工作。
add_filter( 'woocommerce_customer_meta_fields', '__return_empty_array' );
将上面的代码行添加到主题的functions.php 文件中。 完美运行。
只需使用 CSS 来隐藏它。 .class 或 #ID
.class{
display: none!important
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.