Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
1.8 kB
2
Indexable
Never
// display name not required
add_filter('woocommerce_save_account_details_required_fields', 'remove_required_fields');
function remove_required_fields( $required_fields ) {
    unset($required_fields['account_display_name']);
    return $required_fields;
}
add_filter('woocommerce_save_account_details', 'save_required_field');
function save_required_field( $user_id ) {
    if (empty($_POST['account_display_name'])){
    	wp_update_user( array ('ID' => $user_id, 'display_name' => ' '));    

    }
}

add_filter('gettext', 'custom_woocommerce_text', 20, 3);
function custom_woocommerce_text($translated_text, $untranslated_text, $domain) {
    $user_id = get_current_user_id();
    $is_b2b = get_user_meta($user_id, 'b2bking_b2buser', true);
    if ($is_b2b === 'yes'){
        if ($domain === 'woocommerce') {
            switch ($untranslated_text) {
                case 'Display name':
                    $translated_text = __('Business name', 'woocommerce');
                    break;
            }
        }
    }
    return $translated_text;
}

add_action('wp_head', function(){
    $user_id = get_current_user_id();
    $is_b2b = get_user_meta($user_id, 'b2bking_b2buser', true);
    if ($is_b2b !== 'yes'){
        ?>
        <style>
            #account_display_name, label[for="account_display_name"]{
                display: none !important;
            }
        </style>
        <script type="text/javascript">
            jQuery(document).ready(function(){
                jQuery('#account_display_name').parent().remove();
            });
        </script>
        <?php
    } else {
        ?>
        <script type="text/javascript">
            jQuery(document).ready(function(){
                jQuery('#account_display_name').parent().find('span').hide();
            });
        </script>
        <?php
    }
});
Leave a Comment