Automatic invoicing in magento

Automatic invoicing in magento

August 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Automatic invoicing in magento

Automatic Invoicing Control for Custom Product Types in Magento

Managing invoices automatically can streamline your order processing workflow, but there may be instances where you want to manually invoice certain orders based on specific product types. In this guide, we’ll show you how to block automatic invoicing for online payments when an order includes a custom product type that extends the virtual product in Magento.

Understanding Automatic Invoice Generation

By default, Magento triggers automatic invoice generation during payment processing if a product is set as “virtual.” This means that digital or downloadable products get invoiced automatically upon successful payment. However, you can override this behavior for specific custom product types.

Blocking Automatic Invoicing for Custom Product Types

To achieve manual invoicing control for orders containing your custom product type, follow these steps:

1. Create a Custom Invoice Model

First, create a new invoice model that extends the Magento\Sales\Model\Order\Invoice class. This will allow you to customize the invoice generation process.

namespace Magento\Sales\Model;

class CustomInvoice extends \Magento\Sales\Model\Order\Invoice
{
    // Override or extend the desired methods here.
}

2. Override the Invoice Generation Process

In your custom invoice model, override the prepareInvoice method to check if the order contains a product of the type you want to block automatic invoicing for.

public function prepareInvoice()
{
    $order = $this->getOrder();

    // Check if the order contains products of the specified type.
    foreach ($order->getAllItems() as $item) {
        if ($item->getProductType() === 'your_custom_product_type') {
            return false; // Return early to prevent invoice generation.
        }
    }

    // Proceed with default invoice preparation if no custom product types are found.
    return parent::prepareInvoice();
}

3. Configure Automatic Invoice Generation

In your Magento configuration, ensure that the “Automatically Generate Invoices” setting is enabled for the payment methods you want to apply this override to.

Navigate to Stores > Configuration > Sales > Payment Methods and configure the relevant payment method(s). Check the box for “Enable Automatic Invoice Generation.” This ensures that automatic invoicing is triggered by default but allows your custom logic to override it when necessary.

Conclusion

By following these steps, you can effectively block automatic invoicing for online payments in Magento when an order contains a specific custom product type. This approach provides a flexible way to manage invoice generation based on your business requirements.

Remember that extending core models requires careful consideration of the impact on existing functionality and potential upgrade issues. Always test your customizations thoroughly before deploying them to a production environment.

For more advanced techniques in Magento customization, consider exploring our extensive library of tutorials and code examples at Laravel Company. We provide practical guides on various aspects of Magento development, including advanced customizations, performance optimizations, and integration best practices.

Don’t hesitate to reach out if you have any further questions or need expert guidance in implementing this solution for your specific use case.

Catalog Orders

Our network