Adding Total Price to Magento Checkout Success Page
When a customer places an order on your Magento store, they may not remember the total price after navigating away from the checkout page. To help them, you can display the total price on the success page. In this post, we’ll guide you through adding the total price to the success.phtml file in your Magento theme.
Understanding the Checkout Process
Before diving into the code, let’s understand the checkout process:
- The customer adds products to their cart.
- They proceed to checkout, entering shipping and payment information.
- After reviewing the order summary, they click “Place Order”.
- Magento processes the order, saving it to the database.
- The customer is redirected to the success page.
Accessing the Success Page
The success page is determined by a setting in your Magento admin panel:
- Log into your Magento admin area.
- Navigate to Stores > Settings > Configuration.
- Expand the Sales section and click on Checkout.
- Under “Checkout Options”, find the “Onepage Success Page” field.
- Select either “Thank You Page” or create a custom template. For this guide, we’ll use “Thank You Page”.
Adding Total Price to Your Theme
To add the total price to your success page:
-
Navigate to your Magento theme directory via FTP or the file manager in your hosting control panel.
-
Locate the
checkout_onepage_success.phtmlfile inside thetemplatefolder of your active theme.app/design/frontend/<Vendor>/<Theme>/ -
Open this file for editing.
Displaying the Total Price
In the success page template, you can use Magento’s order object to retrieve and display the total price. Update your success.phtml file as follows:
<?php
$order = $this->getOrder();
$totalPrice = $order->formatPrice($order->getGrandTotal());
?>
<p>
Your order has been placed successfully!
<br/>
Total Price: <?php echo $totalPrice; ?>
</p>
<!-- Rest of your success page HTML -->
In this code:
$this->getOrder()retrieves the current order object using Magento’s layout helper.formatPrice($order->getGrandTotal())formats the total price according to your store’s currency settings.
Save the changes and upload the modified file back to your server.
Testing the Changes
To test if the total price is displayed:
- Place an order on your live site (or use a test order).
- Navigate through the checkout process until you reach the success page.
- Verify that the “Total Price” line appears below the “Your order has been placed successfully!” message.
Conclusion
Adding the total price to your Magento checkout success page provides a better user experience by reminding customers of the final amount they need to pay after their order is placed. By following this guide, you can easily incorporate this feature into your store’s theme.
Remember that customizing Magento themes requires careful attention to avoid conflicts when updating your platform. Always back up your files before making changes and consider using version control systems for better management of your modifications.
For more advanced customizations and troubleshooting tips on Magento development, visit Laravel Company.