30 votes

How to show address fields in register

Create local.xml file (if it does not exist already) in [your_package]/[your_theme]/layout/ folder and add following code: <customer_account_create> <reference name="...
user avatar
24 votes

Magento 2: How to add customer address programmatically?

Using Magento\Customer\Api\AddressRepositoryInterface; you can create customer address. namespace {NameSpace}; /** * Description of Address */ class Address { /** * @var Magento\Customer\Api\...
user avatar
  • 75.9k
20 votes

“We can't save the customer” Alert on Magento 2

You most probably have an error somewhere. In order to find out what the problem is you can add this code. $this->messageManager->addException($e, $e->getMessage()); Instead of the line $...
user avatar
  • 196k
13 votes
Accepted

Programatically load default billing and shipping address

This is an example of getting default customer's billing and shipping address if you have the customerId and using the customerRepository Magento\Customer\Api\CustomerRepositoryInterface and the ...
user avatar
  • 2,156
12 votes
Accepted

How can I Get Company Name from customer Billing Address in Customer information tab in Admin?

You can get the company name inside app/design/adminhtml/default/default/template/customer/tab/view.phtml by using the following code: Getting the company name from the billing address: <?php ...
user avatar
  • 17.2k
12 votes
Accepted

How to get customer address by customer ID?

You cannot retrieve an address based on the customer id so this code will never work: $address = $this->_addressRepository->getByCustomerId($customerId);//error Because the getByCustomerId ...
user avatar
10 votes

How to add a customer custom-attribute in the customer address edit form?

Custom customer attributes will never just 'appear' on the frontend like they do in the backend. The code that displays them on the frontend is located in a custom phtml file. Magento EE has this ...
user avatar
  • 1,196
9 votes

How do I add a customer's email to the sales invoice?

You can get the customer email like this in the invoice or order templates: {{var order.getCustomerEmail()}} SO you can try to add Email: {{var order.getCustomerEmail()}} after {{var order....
user avatar
  • 196k
9 votes
Accepted

Custom module to add a 3rd customer address type

First of all I want to say that the address_type is not used for customer addresses. It is used only for quote and order addresses, so there is no need to use that in order to flag your own address ...
user avatar
  • 196k
9 votes
Accepted

How to retrieve a customer by phone number?

You can do this via the customer address collection as the phone number is part of a customer's address. If the phone number given by $phoneNumber and the one in the customer's address literally ...
user avatar
  • 7,362
9 votes
Accepted

Limit country drop down input field Magento 2

Please allow only that need from Admin > Stores > Configuration > General > Country Options > Allow Countries
user avatar
8 votes
Accepted

How to add a new address (shipping or billing or another) via Magento 2 REST API?

I was having a similar problem and was digging into the AccountManagement class to find the proper payload. I noticed that the createAccount function checks if a customer ID exists and loads the ...
user avatar
  • 96
8 votes
Accepted

Update customer address using address id in magento 2

If you know the address id ($addressId) you can use the address repository to load and save updated addresses: /** * @var \Magento\Customer\Api\AddressRepositoryInterface */ protected $...
user avatar
8 votes
Accepted

Multiselect attribute not saving in Magento 2.3.0

When creating the customer attribute, please take care about following things: Attribute is added to the attribute set, group customer_eav_attribute eav_entity_attribute Attribute is assigned ...
user avatar
  • 2,493
7 votes

Programatically update customer address by its entity id

Replace this $address->setData($addressCode, $addressData[$addressValue]); with $address->setData($addressCode, $addressValue); <?php $addressId = '5'; $addressData = array( ...
user avatar
7 votes

How to get customer address by customer ID?

For get customer adderess using order id in .phtml file $customerId = 3; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerObj = $objectManager->create('Magento\...
user avatar
7 votes
Accepted

Magento 2 Customer Listing action: get customer's telephone

The telephone number is related to the customer's addresses and not to the customer's account. So a solution will be to get the customer's default billing or shipping and get the telephone number ...
user avatar
  • 2,156
7 votes
Accepted

Magento 2.X - "Invalid Customer Address Id" comes randomly for the customers on checkout

I've checked it further and fixed this issue by overriding Magento's validateForCart function. /** * Validate address to be used for cart. * * @param CartInterface $cart * @param AddressInterface $...
user avatar
  • 4,705
6 votes

Check if customer has address?

$customer->getAddresses() should return all customer addresses so count($customer->getAddresses()) should return quantity of addresses of customer. you can check like if(count($customer->...
user avatar
  • 2,577
6 votes

How to add a new address (shipping or billing or another) via Magento 2 REST API?

It should be possible to add/update customer addresses using customer repository API: PUT /V1/customers/:id (for admin) PUT /V1/customers/me (for customer)
user avatar
6 votes
Accepted

how to display the address fields in the registration form

Create customer_account_create.xml file your current active theme For eg. app/design/frontend/{YOUR_PACKAGE}/{YOUR_THEME}/Magento_Customer/layout/customer_account_create.xml After add below ...
user avatar
  • 9,552
5 votes

Magento 2 Get shipping and billing address of customer after order placed?

You can add this piece of code in the file: <?php /** @var $_order \Magento\Sales\Model\Order */ ?> <?php $_order = $block->getOrder() ?> <?php $billingAddress = $_order->...
user avatar
  • 1,600
5 votes
Accepted

How to Make First and Last Name Optional for addresses?

Here's a simple method that can be used to make any required address field optional. First create a plugin for Magento\Checkout\Block\Checkout\LayoutProcessor. Define the class as follow: <?php ...
user avatar
  • 8,819
5 votes
Accepted

Customer Address custom attribute not showing front end in Magento 2

Customer Address edit form won't automatically generate custom attribute. You have to override template file vendor/magento/module-customer/view/frontend/templates/address/edit.phtml to show it in ...
user avatar
  • 1,688
5 votes

How to update customer address using custom Api in magento2?

You need to call below api for customer address update API : xyz.com/rest/V1/customers/2 Header: Authorization :"Bearer ishamls4xu7pnwhlvup141502tjm3cl2" Content-Type :"application/json" Method : ...
user avatar
5 votes

Magento 2: How to add customer address programmatically?

Please try with following code. $customerId = 10 $addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory'); $address = $addresss->create(); $address->setCustomerId($...
user avatar
5 votes

Magento 2 checkout address buttons are missing and the developer console shows a customAttributes error

For this kind of issue, it's really hard to find the root cause. Magento is hard, Js is hard. My suggestion is to use Debugger. Chrome Devtools: https://developers.google.com/web/tools/chrome-...
user avatar
5 votes
Accepted

How to get Customer Address in formated way and print it - Magento2.3

create Model app/code/VendoreName/ModuleName/Model CustomerAddress.php <?php namespace VendoreName\ModuleName\Model; use Magento\Framework\Model\AbstractModel; use VendoreName\ModuleName\Model\...
user avatar
  • 6,063
4 votes

How do I add a customer's email to the sales invoice?

There is an easier way to add it to all customer configuration emails. Just rewrite Mage_Customer_Helper_Address and it to the customer address attribute list. So open up System > Configuration > ...
user avatar
4 votes
Accepted

How can I create and retrieve default billing address programatically?

You need to set it the other way around. The default_billing for the customer. $customerId = 1234; // Customer id $data = array(); // Address data $customer = Mage::getModel('customer/customer'); //...
user avatar
  • 2,948

Only top scored, non community-wiki answers of a minimum length are eligible