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 Create a Shopify Draft Order in Shopify Remix Using GraphQL?

Shopify's Draft Orders feature is an essential tool for merchants, allowing them to create orders…

12 hours ago

How to Use CSS with Shopify Remix Vite?

CSS (Cascading Style Sheets) is essential in web development to create visually appealing and responsive…

1 day ago

Latest Hyvä Theme Trends to Elevate your Magento UI/UX

Your eCommerce website theme is highly important for your business's online success as it reflects…

2 days ago

Use Hyvä Products at their Full Potential

Hyvä represents more than just a theme; it is a comprehensive suite of extensions and…

2 days ago

Magento 2: Add Number of Products Displayed Per Page in Invoice PDF

Hello Magento mates, Invoices are critical documents in every eCommerce business, providing details of product…

4 days ago

SearchGPT vs. ChatGPT: Key Differences, Advantages, and Future Trends

In recent years, artificial intelligence (AI) has made remarkable strides, with models like ChatGPT and…

1 week ago