0

After adding a custom customer attribute with a dropdown, having values 'A (11)' and 'B (12)', I attempted to display the attributes on the customer account page. However, upon adding the following code to the 'info.phtml' file, I received values instead of names.

https://prnt.sc/UE6AIMR5uiZj

<?php     
 $customAttribute = $block->getCustomer()->getCustomAttribute('customer_name');
 if ($customAttribute) {
      echo $block->escapeHtml($customAttribute->getValue());
 }
?>
4
  • Are you got the proper value for the custom attribute? Commented Apr 3 at 5:52
  • Which type of attribute, you have created? Commented Apr 3 at 5:59
  • Drop down multi select
    – kiran
    Commented Apr 3 at 10:54
  • Yes, proper value
    – kiran
    Commented Apr 3 at 10:54

1 Answer 1

-1

Please use the code provided below to display custom attributes on the frontend dashboard.

 <?php
            $customer = $block->getCustomer();
            if ($customer) {
                $customerNameAttribute = $customer->getCustomAttribute('customer_name');
                if ($customerNameAttribute) {
                    $customerNameValue = $customerNameAttribute->getValue();
                    $mappedText = ''; 
                    switch ($customerNameValue) {
                        case '11':
                            $mappedText = __('Car');
                            break;
                        case '10':
                            $mappedText = __('Bus');
                            break;
                        default:
                            $mappedText = __('Unknown');
                            break;
                    }
            ?>
                    <div class="">
                        <strong class="">
                            <span><?= $block->escapeHtml(__('Types : ')) ?></span>
                        </strong>
                        
                            <?= $block->escapeHtml($mappedText) ?>
                        
                    </div>
            <?php
                }
            }
            ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.