<p>I have return $addressLines; when it should be <code>$event-&gt;addressLines = $addressLines;</code>. In an event the idea is to manipulate the event variables, these will then be used by the code later on. My full event code would look like:</p>
<pre><code>Event::on(Address::class, Address::EVENT_DEFINE_ADDRESS_LINES, function(DefineAddressLinesEvent $event) {
    // @var array $addressLines
    $addressLines = $event-&gt;addressLines;
    // Modify default address lines array
    $addressLinesNewOrder = [
        'attention',
        'name',
        'fullName',
        'address1',
        'address2',
        'address3',
        'city',
        'zipCode',
        'stateText',
        'countryText',
        'phone',
        'alternativePhone',
        'label',
        'notes',
        'businessName',
        'businessTaxId',
        'custom1',
        'custom2',
        'custom3',
        'custom4',
    ];
    uksort($addressLines, function($x, $y) use ($addressLinesNewOrder) {
        return array_search($x, $addressLinesNewOrder) &gt; array_search($y, $addressLinesNewOrder);
    });

    $event-&gt;addressLines = $addressLines;
});
</code></pre>

CC BY-SA 4.0
2022-02-11T11:28:30.427Z
2022-02-11T11:28:30.427Z
John Henry Donovan
<p>I have a plugin to reorder the address lines in Commerce. Basically to move the Phone Number to the bottom as it drives all my clients nuts.</p>
<p>While the final array, <code>addressLines</code> is the correct array and all looks ok it does not seem to be passing <code>$addressLines</code> back into getAddressLines function in <em>/src/models/Address.php</em> Am I missing the obvious here or is there a bug?</p>
<pre><code>Event::on(
            Address::class,
            Address::EVENT_DEFINE_ADDRESS_LINES,
            function(DefineAddressLinesEvent $event) {
                // @var array $addressLines
                $addressLines = $event-&gt;addressLines;
                // Modify default address lines array
                $addressLinesNewOrder = [
                    'attention',
                    'name',
                    'fullName',
                    'address1',
                    'address2',
                    'address3',
                    'city',
                    'zipCode',
                    'stateText',
                    'countryText',
                    'phone',
                    'alternativePhone',
                    'label',
                    'notes',
                    'businessName',
                    'businessTaxId',
                    'custom1',
                    'custom2',
                    'custom3' ,
                    'custom4',
            ];
            uksort($addressLines, function($x, $y) use ($addressLinesNewOrder) {
                return array_search($x, $addressLinesNewOrder) &gt; array_search($y, $addressLinesNewOrder);
          });

        return $addressLines;

    });
</code></pre>
<p><a href="https://craftcms.com/docs/commerce/3.x/addresses.html#address-lines" rel="nofollow noreferrer">https://craftcms.com/docs/commerce/3.x/addresses.html#address-lines</a>
<a href="https://craftcms.com/docs/commerce/3.x/extend/events.html#defineaddresslines" rel="nofollow noreferrer">https://craftcms.com/docs/commerce/3.x/extend/events.html#defineaddresslines</a></p>

CC BY-SA 4.0
2021-04-23T13:25:17.830Z
Added Github issue here https://github.com/craftcms/commerce/issues/2104
John Henry Donovan
<plugin-craftcommerce><plugins><addresses>
EVENT_DEFINE_ADDRESS_LINES not pushing response back to Craft Commerce
# EVENT_DEFINE_ADDRESS_LINES not pushing response back to Craft Commerce

(Asked by: username_0 on 2021-03-15)

I have a plugin to reorder the address lines in Commerce. Basically to move the Phone Number to the bottom as it drives all my clients nuts.
While the final array, addressLines is the correct array and all looks ok it does not seem to be passing $addressLines back into getAddressLines function in /src/models/Address.php Am I missing the obvious here or is there a bug?
Event::on(
            Address::class,
            Address::EVENT_DEFINE_ADDRESS_LINES,
            function(DefineAddressLinesEvent $event) {
                // @var array $addressLines
                $addressLines = $event->addressLines;
                // Modify default address lines array
                $addressLinesNewOrder = [
                    'attention',
                    'name',
                    'fullName',
                    'address1',
                    'address2',
                    'address3',
                    'city',
                    'zipCode',
                    'stateText',
                    'countryText',
                    'phone',
                    'alternativePhone',
                    'label',
                    'notes',
                    'businessName',
                    'businessTaxId',
                    'custom1',
                    'custom2',
                    'custom3' ,
                    'custom4',
            ];
            uksort($addressLines, function($x, $y) use ($addressLinesNewOrder) {
                return array_search($x, $addressLinesNewOrder) > array_search($y, $addressLinesNewOrder);
          });

        return $addressLines;

    });

https://craftcms.com/docs/commerce/3.x/addresses.html#address-lines
https://craftcms.com/docs/commerce/3.x/extend/events.html#defineaddresslines

**Tags:** plugin-craftcommerce, plugins, addresses

> **Comments:**
> **username_0**: Added Github issue here https://github.com/craftcms/commerce/issues/2104  

---

## 1 answers

### Answer by username_0 on 2022-02-11. Score: 1 | Accepted answer

I have return $addressLines; when it should be $event->addressLines = $addressLines;. In an event the idea is to manipulate the event variables, these will then be used by the code later on. My full event code would look like:
Event::on(Address::class, Address::EVENT_DEFINE_ADDRESS_LINES, function(DefineAddressLinesEvent $event) {
    // @var array $addressLines
    $addressLines = $event->addressLines;
    // Modify default address lines array
    $addressLinesNewOrder = [
        'attention',
        'name',
        'fullName',
        'address1',
        'address2',
        'address3',
        'city',
        'zipCode',
        'stateText',
        'countryText',
        'phone',
        'alternativePhone',
        'label',
        'notes',
        'businessName',
        'businessTaxId',
        'custom1',
        'custom2',
        'custom3',
        'custom4',
    ];
    uksort($addressLines, function($x, $y) use ($addressLinesNewOrder) {
        return array_search($x, $addressLinesNewOrder) > array_search($y, $addressLinesNewOrder);
    });

    $event->addressLines = $addressLines;
});


---

