Adding Flat Rate Shipping Costs to Magento Grand Total
As an online merchant using Magento 1.9, you might find yourself needing to add a flat rate shipping cost to your cart’s grand total while keeping the prices displayed in the admin panel tax-exclusive. Let me walk you through this process step-by-step.
Understanding the Current Issue
The issue at hand is that Magento currently adds up all product prices (subtotal) and displays the same amount as the grand total, without considering any additional costs like flat rate shipping charges. You want to add a fixed shipping cost of 5.95 while keeping your administrative pricing scheme tax-exclusive.
Step-by-Step Solution
Enable Flat Rate Shipping Method
First, ensure you have enabled the flat rate shipping method in your Magento admin panel. Navigate to System > Configuration > Sales > Shipping Methods. Locate the Flat Rate option and set its status to Enabled.
Learn more about configuring shipping methods on our Magento tutorial page.
Create a Flat Rate Shipping Cost
Next, you need to create a flat rate shipping cost. Go to System > Configuration > Sales > Tax. Under the Shipping Tax Class field, select the tax class that corresponds with your shipping rate (usually None). This ensures your flat rate is displayed tax-exclusive.
Modify the Cart Total Block
To add the flat rate shipping cost to the grand total, you’ll need to modify the cart totals block. Open the app/design/frontend/base/default/template/checkout/cart.phtml file in a text editor.
Around line 240, locate the following PHP code:
echo $this->getChildHtml('totals');
This is where you’ll add your flat rate shipping cost. Wrap this line with an if statement to check if the customer logged in and the grand total isn’t already set:
<?php if ($this->helper('customer')->isLoggedIn() && !isset($grandTotal)): ?>
<?php echo $this->getChildHtml('totals'); ?>
<?php endif; ?>
Explore more about customizing checkout totals in our in-depth Magento guide.
Conclusion
Adding a flat rate shipping cost to your Magento grand total involves enabling the Flat Rate shipping method, setting up the cost tax-exclusively, and then modifying the cart totals block. By following this approach, you can maintain tax-exclusive administrative pricing while displaying inclusive prices in the frontend.
Remember that customizing core files like cart.phtml should be done via a child theme or a layout update XML file to preserve your changes across Magento updates. Always backup your data before making these modifications.
Happy coding, and feel free to explore more Magento tips and tricks on our blog at Laravel Company.