How to Fix Customer Name Prefix/Suffix Showing as Numbers in Address in Magento 2


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;

    }

}



Comments

Popular posts from this blog

Add Admin User name and Action name in Order Comment Section through Action Performed from Sales Order Grid in Magento 2

How to Update Product Stock Programmatically in Magento 2

How to Set and Get Cookie in Magento 2