How To

Magento 2: How to Call phtml Based on Selection of Payment Method at Multishipping Payment

Hello Magento Friends,

Multishipping in Magento 2 allows customers to split their orders into multiple shipments with different shipping addresses, making it a valuable feature for those ordering gifts or sending products to various locations. When configuring the checkout process in Magento 2, especially with multiple shipping addresses, calling a specific PHTML file based on the selected payment method can enhance the checkout experience, making it more dynamic and tailored to the payment method chosen by the customer.

In this blog, we’ll walk through the process of how to call a PHTML file based on the selection of the payment method during the multishipping payment stage in Magento 2.

Steps to Call phtml Based on Selection of Payment Method at Multishipping Payment in Magento 2:

Step 1: We need to create a “multishipping_checkout_billing.xml“ file inside our extension at the following path.

app\code\Vendor\Extension\view\frontend\layout\multishipping_checkout_billing.xml

Then add the code as follows

<?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="checkout_billing">
            <arguments>
                <argument name="form_templates" xsi:type="array">
                    <item name="cashondelivery" xsi:type="string">Vendor_Extension::checkout/fileforcashondelivery.phtml</item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

Step 2: We need to create a “fileforcashondelivery.phtml“ file inside our extension at the following path.

app\code\Vendor\Extension\view\frontend\templates\checkout\fileforcashondelivery.phtml

Now, add the code as given below

<?php 
    echo "COD Verfication Block.";
?>

Output:

Conclusion

With this approach, you can dynamically call a PHTML file based on the payment method selection in Magento 2’s multishipping payment process. This adds a layer of flexibility, allowing you to display custom content, instructions, or additional details specific to each payment method. By following the outlined steps, you can easily manage the PHTML rendering without impacting the core Magento functionality.

Click to rate this post!
[Total: 0 Average: 0]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

How to Add Tooltip in Checkout Shipping Field in Magento 2?

Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…

2 days ago

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

3 days ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

4 days ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

6 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

1 week ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

1 week ago