Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 隐藏WooCommerce中客户用户角色的结帐帐单字段_Php_Woocommerce - Fatal编程技术网

Php 隐藏WooCommerce中客户用户角色的结帐帐单字段

Php 隐藏WooCommerce中客户用户角色的结帐帐单字段,php,woocommerce,Php,Woocommerce,问题:如何添加只根据用户角色(在本例中为客户)隐藏账单字段的代码 使用以下代码,我们可以对登录用户隐藏购物车中的账单详细信息: add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' ); function custom_override_checkout_fields( $fields ) { if( is_user_logged_in() ){ exec($fields[

问题:如何添加只根据用户角色(在本例中为客户)隐藏账单字段的代码

使用以下代码,我们可以对登录用户隐藏购物车中的账单详细信息:

add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
    if( is_user_logged_in() ){
        exec($fields['billing']);
        $fields['billing'] = array();
    }
    return $fields;
}
使用与用户角色配合使用的WordPress条件函数,如:

add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
    if( current_user_can('customer') ){
        exec($fields['billing']);
        $fields['billing'] = array();
    }
    return $fields;
}

代码进入活动子主题(或活动主题)的function.php文件。它应该可以工作。

出于某种原因,在我的例子中,这仍然显示了
账单名称字段。还有头。以下代码可以正常工作:

add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
    if( current_user_can('customer') ){
        exec($fields['billing']);
        unset($fields['billing']); //this was changed
    }
    return $fields;
}