1

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

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.