How to set default shipping address of the customer Magento 2?

Set Default shipping address id of the customer in Magento 2 using Address Repository Interface.

You required Customer Id to set shipping address and address id you want to assign it.

First, load the existing address by the getById method of the address repository interface with the set customer. Continue reading “How to set default shipping address of the customer Magento 2?”

How to override address/grid.phtml in Magento 2?

You can override the grid.phtml file to manage additional addresses of the customer.

If the customer has multiple addresses available, it will be displayed in the Additional Address Entries section of the Address book page. You can add/update the new column to the address list on the page using overriding grid template file.

Magento\Customer\Block\Address\Grid Block class is used to manage the grid template file. You can override using theme or module level,

1. Theme Level,

app/design/frontend/{Vendor}/{themename}/Magento_Customer/templates/address/grid.phtml

2. Module Level,
When you explore the customer_address_index.xml file from the customer module, You can see the address_book block that will be used to display an address book page on the frontend.

File Path: app/code/Jesadiya/Book/view/frontend/layout/customer_address_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="address_grid">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Jesadiya_Book::address/grid.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Create Template file to override grid.phtml,
app/code/Jesadiya/Book/view/frontend/templates/address/grid.phtml

Keep the required content from the Core template and modify your changes. You can also override Address book.phtml in Magento 2

Clear Cache to see changes,
php bin/magento cache:flush

How to override address/book phtml in Magento 2?

You can override the book.phtml file in Magento 2 using XML.
Book template used to display the address book of the customer with default billing and shipping address at the top of the Address book page.

Magento\Customer\Block\Address\Book

Book Block class contains the native method for the template.
You can override using theme or module level, Continue reading “How to override address/book phtml in Magento 2?”