{"id":45274,"date":"2016-04-08T12:57:36","date_gmt":"2016-04-08T12:57:36","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=45274"},"modified":"2024-02-23T09:57:43","modified_gmt":"2024-02-23T09:57:43","slug":"add-custom-pricefee-order-total-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/","title":{"rendered":"How to Add Custom Price\/fee in Order total in Magento 2"},"content":{"rendered":"\n<p>If you want to add a custom price\/custom fee to your total, then you can use the following approach.<\/p>\n\n\n\n<p>create sales.xml in your module etc folder<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:module:Magento_Sales:etc\/sales.xsd&quot;&gt;\n    &lt;section name=&quot;quote&quot;&gt;\n        &lt;group name=&quot;totals&quot;&gt;\n            &lt;item name=&quot;customfee&quot; instance=&quot;Webkul\\Test\\Model\\Total\\Customfee&quot; sort_order=&quot;150&quot;\/&gt;\n        &lt;\/group&gt;  \n    &lt;\/section&gt;\n&lt;\/config&gt;<\/pre>\n\n\n\n<p>Now, define\u00a0app\\code\\Webkul\\Test\\Model\\Total\\Customfee.php, where you update your total according to your custom fee.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">class Customfee extends \\Magento\\Quote\\Model\\Quote\\Address\\Total\\AbstractTotal\n{\n   \/**\n     * Collect grand total address amount\n     *\n     * @param \\Magento\\Quote\\Model\\Quote $quote\n     * @param \\Magento\\Quote\\Api\\Data\\ShippingAssignmentInterface $shippingAssignment\n     * @param \\Magento\\Quote\\Model\\Quote\\Address\\Total $total\n     * @return $this\n     *\/\n    protected $quoteValidator = null; \n\n    public function __construct(\\Magento\\Quote\\Model\\QuoteValidator $quoteValidator)\n    {\n        $this-&gt;quoteValidator = $quoteValidator;\n    }\n  public function collect(\n        \\Magento\\Quote\\Model\\Quote $quote,\n        \\Magento\\Quote\\Api\\Data\\ShippingAssignmentInterface $shippingAssignment,\n        \\Magento\\Quote\\Model\\Quote\\Address\\Total $total\n    ) {\n        parent::collect($quote, $shippingAssignment, $total);\n\n\n        $exist_amount = 0; \/\/$quote-&gt;getCustomfee(); \n        $customfee = 100; \/\/enter amount which you want to set\n        $balance = $customfee - $exist_amount;\/\/final amount\n\n        $total-&gt;setTotalAmount(&#039;customfee&#039;, $balance);\n        $total-&gt;setBaseTotalAmount(&#039;customfee&#039;, $balance);\n\n        $total-&gt;setCustomfee($balance);\n        $total-&gt;setBaseCustomfee($balance);\n\n        $total-&gt;setGrandTotal($total-&gt;getGrandTotal() + $balance);\n        $total-&gt;setBaseGrandTotal($total-&gt;getBaseGrandTotal() + $balance);\n\n\n        return $this;\n    } \n\n    protected function clearValues(Address\\Total $total)\n    {\n        $total-&gt;setTotalAmount(&#039;subtotal&#039;, 0);\n        $total-&gt;setBaseTotalAmount(&#039;subtotal&#039;, 0);\n        $total-&gt;setTotalAmount(&#039;tax&#039;, 0);\n        $total-&gt;setBaseTotalAmount(&#039;tax&#039;, 0);\n        $total-&gt;setTotalAmount(&#039;discount_tax_compensation&#039;, 0);\n        $total-&gt;setBaseTotalAmount(&#039;discount_tax_compensation&#039;, 0);\n        $total-&gt;setTotalAmount(&#039;shipping_discount_tax_compensation&#039;, 0);\n        $total-&gt;setBaseTotalAmount(&#039;shipping_discount_tax_compensation&#039;, 0);\n        $total-&gt;setSubtotalInclTax(0);\n        $total-&gt;setBaseSubtotalInclTax(0);\n    }\n    \/**\n     * @param \\Magento\\Quote\\Model\\Quote $quote\n     * @param Address\\Total $total\n     * @return array|null\n     *\/\n    \/**\n     * Assign subtotal amount and label to address object\n     *\n     * @param \\Magento\\Quote\\Model\\Quote $quote\n     * @param Address\\Total $total\n     * @return array\n     *\/\n    public function fetch(\\Magento\\Quote\\Model\\Quote $quote, \\Magento\\Quote\\Model\\Quote\\Address\\Total $total)\n    {\n        return &#091;\n            &#039;code&#039; =&gt; &#039;customfee&#039;,\n            &#039;title&#039; =&gt; &#039;Custom Fee&#039;,\n            &#039;value&#039; =&gt; 100\n        ];\n    }\n\n    \/**\n     * Get Subtotal label\n     *\n     * @return \\Magento\\Framework\\Phrase\n     *\/\n    public function getLabel()\n    {\n        return __(&#039;Custom Fee&#039;);\n    }\n}<\/pre>\n\n\n\n<p>I hope this blog will help you with How to Add Custom Prices\/fees in Order total in Magento 2. You may also check our wide range of best\u00a0<a href=\"https:\/\/store.webkul.com\/Magento-2.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Extensions<\/a>.<\/p>\n\n\n\n<p>Please reach out to our team via a&nbsp;<a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\" target=\"_blank\" rel=\"noreferrer noopener\">support ticket<\/a>&nbsp;if you have any queries.<\/p>\n\n\n\n<p>Try this and if you have any queries then just comment below \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to add a custom price\/custom fee to your total, then you can use the following approach. create sales.xml in your module etc folder Now, define\u00a0app\\code\\Webkul\\Test\\Model\\Total\\Customfee.php, where you update your total according to your custom fee. I hope this blog will help you with How to Add Custom Prices\/fees in Order total in <a href=\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":68,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[2070],"class_list":["post-45274","post","type-post","status-publish","format-standard","hentry","category-magento2","tag-magento2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Add Custom Price\/fee in Order total in Magento 2<\/title>\n<meta name=\"description\" content=\"In this blog we will discuss How to Add Custom Price\/fee in Order total in Magento 2\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Add Custom Price\/fee in Order total in Magento 2\" \/>\n<meta property=\"og:description\" content=\"In this blog we will discuss How to Add Custom Price\/fee in Order total in Magento 2\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-04-08T12:57:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-23T09:57:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Bulbul\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bulbul\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/\"},\"author\":{\"name\":\"Bulbul\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e\"},\"headline\":\"How to Add Custom Price\/fee in Order total in Magento 2\",\"datePublished\":\"2016-04-08T12:57:36+00:00\",\"dateModified\":\"2024-02-23T09:57:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/\"},\"wordCount\":118,\"commentCount\":10,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"Magento2\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/\",\"name\":\"How to Add Custom Price\/fee in Order total in Magento 2\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2016-04-08T12:57:36+00:00\",\"dateModified\":\"2024-02-23T09:57:43+00:00\",\"description\":\"In this blog we will discuss How to Add Custom Price\/fee in Order total in Magento 2\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Add Custom Price\/fee in Order total in Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e\",\"name\":\"Bulbul\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Bulbul\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/bulbul896\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Add Custom Price\/fee in Order total in Magento 2","description":"In this blog we will discuss How to Add Custom Price\/fee in Order total in Magento 2","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/","og_locale":"en_US","og_type":"article","og_title":"How to Add Custom Price\/fee in Order total in Magento 2","og_description":"In this blog we will discuss How to Add Custom Price\/fee in Order total in Magento 2","og_url":"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-04-08T12:57:36+00:00","article_modified_time":"2024-02-23T09:57:43+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Bulbul","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Bulbul","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/"},"author":{"name":"Bulbul","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e"},"headline":"How to Add Custom Price\/fee in Order total in Magento 2","datePublished":"2016-04-08T12:57:36+00:00","dateModified":"2024-02-23T09:57:43+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/"},"wordCount":118,"commentCount":10,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["Magento2"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/","url":"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/","name":"How to Add Custom Price\/fee in Order total in Magento 2","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2016-04-08T12:57:36+00:00","dateModified":"2024-02-23T09:57:43+00:00","description":"In this blog we will discuss How to Add Custom Price\/fee in Order total in Magento 2","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/add-custom-pricefee-order-total-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Add Custom Price\/fee in Order total in Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e","name":"Bulbul","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Bulbul"},"url":"https:\/\/webkul.com\/blog\/author\/bulbul896\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/45274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=45274"}],"version-history":[{"count":9,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/45274\/revisions"}],"predecessor-version":[{"id":424042,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/45274\/revisions\/424042"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=45274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=45274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=45274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}