Hello Magento Friends,
In this blog, we will learn about How to Fix Customer Name Prefix/Suffix Showing as Numbers in Address in Magento 2.
Prefixes and Suffixes are added to customers’ names in order to group them based on their marital status, qualification, etc. Learn How to Add Prefix and Suffix in Magento 2.
In Magento 2, order summary billing and shipping address instead of prefix/suffix of customer’s name, it is displayed number. Instead of name prefixes like Mr., Mrs., or Dr., it displays numbers. Go ahead to know the solution to this issue.
Steps to Fix Customer Name Prefix/Suffix Showing as Numbers in Address in Magento 2:
Step 1: First, we need to create a “di.xml” file inside the extension etc directory of our extension at the following path.
app\code\Vendor\Extension\etc
Now add the code as follows
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Customer\Model\Options"> <plugin name="customer_prefix_issue" type="Vendor\Extension\Plugin\ChangePrefixOption"/> </type> </config>
Step 2: After that, we need to create a “ChangePrefixOption.php” file inside the extension at the following path.
app\code\Vendor\Extension\Plugin
And append the below code-snippet
<?php namespace Vendor\Extension\Plugin; use Magento\Customer\Model\Options; class ChangePrefixOption { public function afterGetNamePrefixOptions(Options $subject, array|bool $result): array|bool { if (!is_array($result)) { return $result; } $prefixArray = []; foreach ($result as $prefixValue) { $prefixArray[$prefixValue] = $prefixValue; } return $prefixArray; } }
Conclusion:
Hence, using the above steps, you can Fix Customer Name Prefix/Suffix Showing as Numbers in Address in Magento 2. If you face any difficulty, share it with me through the comment box. Share the solution with your friends and stay in touch with us.
Happy Coding!