How to disable Magento invoices on the frontend

How to disable Magento invoices on the frontend

August 26, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to disable Magento invoices on the frontend

Hiding Magento Invoices from the Frontend: A Comprehensive Guide

As an e-commerce developer working with Magento 1.7 stores, you may find yourself needing to disable frontend access to invoices for various reasons - legal compliance, security, or integration with third-party systems like we’re dealing with here.

The Challenge: Customers Accessing Invalid Invoices

You’ve already discovered one potential solution by editing the sales.xml layout file in your theme folder. However, you’re rightfully concerned about customers being able to access invoices directly via their URL path.

Let’s explore a more robust and secure approach that ensures Magento doesn’t even generate these URLs or allow customer access through them.

Why Disabling Invoices Isn’t Enough

Before we dive into the solution, it’s crucial to understand why simply removing invoice links from the frontend isn’t enough. When you disable invoices in the admin area, Magento still generates invoice files and URLs for each order. These can be accessed directly by customers if they have the URL path (which is easily discovered).

The Best Practice: Controlling Invoice Access at the Core

To truly prevent customer access to invoices, we need to modify Magento’s core behavior. This involves editing the sales_order_invoice model to restrict the ‘can view invoice’ attribute and preventing the creation of invoice files.

Here’s a step-by-step guide:

  1. Editing the sales_order_invoice Model

Open the file /app/code/core/Mage/Sales/Model/Order/Invoice.php. Add the following code after line 37, before the class Mage_Sales_Model_Order_Invoice declaration:

public function canViewInvoice(Mage_Customer_Model_Customer $customer)
{
    return false;
}

This method is responsible for determining if a customer can view an invoice. By returning false, we’re explicitly preventing any customer from being able to view their invoices.

  1. Preventing Invoice File Creation

Now, let’s prevent Magento from creating the physical invoice PDF files in the first place. This step isn’t strictly necessary since customers won’t be able to access them even if they exist, but it helps manage file clutter.

Open the file /app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php. Find the _preparePdf() method (around line 120) and replace its content with this:

protected function _preparePdf()
{
    // Prevent invoice PDF creation
    return false;
}

This tells Magento not to generate invoice PDF files when an order is invoiced.

Verifying Your Changes

After making these modifications, clear your cache. You can do this through the Magento admin interface under System > Cache Management or by manually deleting the contents of the var/cache folder.

Now, test the changes:

  • In the backend, create a new invoice for an order.
  • Check if the ‘Invoice’ link is missing from the customer’s account in the frontend.
  • Verify that the invoice PDF file was not created in the media/orderexport/invoice/ directory.

Conclusion

By modifying Magento’s core model behavior, we’ve successfully prevented customers from viewing or accessing invoices through any means - links, URLs, or directly. This approach ensures compliance with European law and allows you to manage invoicing independently using your third-party application.

Remember, editing core files should always be done with caution. It’s a good practice to use the app/code/local folder instead of core, which is reserved for Magento’s official extensions.

If this solution doesn’t meet your specific needs or if you’re working on an e-commerce platform other than Magento, consider exploring our e-commerce development services at Laravel Company. Our team specializes in custom solutions and can help you navigate complex e-commerce challenges like this one.

Happy coding!

Magento 1 Security API Themes

Our network