Menu Close
    Hire Us Request Quote Reading List Switch to Dark Mode

    Add custom fee in downloaded PDF of an order magento2


    To add order’s custom fee amount field in PDF which is downloaded either from admin or from frontend, to can use following process:

    Firstly you have to create pdf.xml at path :


    <?xml version="1.0"?>
    <config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/pdf_file.xsd">
            <total name="custom_fee">
                <title translate="true">Custom Fee</title>

    Here, source_field: is the field name which you created as a field in order.

    model: is the file in model in which you code to add field in totals.

    font_size: default font_size is 7 you can change it.

    display_zero: If you don’t want to display field if amount is 0 then set it to false, otherwise set it to true.

    sort_order: sort order for the position of your field.

    Now create file at path:  app\code\Webkul\Test\Model\Sales\Pdf\Customfee.php

    namespace Webkul\Test\Model\Sales\Pdf;
    class Customfee extends \Magento\Sales\Model\Order\Pdf\Total\DefaultTotal
        public function getTotalsForDisplay()
            $amount = $this->getOrder()->formatPriceTxt($this->getAmount());
            if ($this->getAmountPrefix()) {
                $amount = $this->getAmountPrefix() . $amount;
            $title = __($this->getTitle());
            if ($this->getTitleSourceField()) {
                $label = $title . ' (' . $this->getTitleDescription() . '):';
            } else {
                $label = $title . ':';
            $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
            $total = ['amount' => $amount, 'label' => $label, 'font_size' => $fontSize];
            return [$total];

    after this your field will be added in downloaded pdf of an order.

    Here are some related links for managing custom fee in order:

    Add Custom Price Fee In Order Total Magento2

    Display Custom Price Fee On Checkout Cart Summary Total Magento2

    Display Custom Price Fee On Sales Order View Page

    Hope it will help you.

    Thank you.

    . . .


    Add Your Comment

    Be the first to comment.

    Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again