{"id":389556,"date":"2023-07-04T11:53:47","date_gmt":"2023-07-04T11:53:47","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=389556"},"modified":"2023-07-18T09:33:44","modified_gmt":"2023-07-18T09:33:44","slug":"modify-total-on-the-checkout-page-in-magento-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/","title":{"rendered":"Modify Total on the checkout page in Magento 2"},"content":{"rendered":"\n<p>Hello Friends!!<\/p>\n\n\n\n<p>In today\u2019s blog, I will explain how we can modify the total on the checkout page.<\/p>\n\n\n\n<p>This blog is useful if you need to update the total based on any condition only on the checkout page.<\/p>\n\n\n\n<p>First of all, we will create a sales.xml file inside the, etc folder. You can simply use the below code in your sales.xml file. <\/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;updatetotal&quot; instance=&quot;Webkul\\Test\\Model\\Total\\UpdateTotal&quot; sort_order=&quot;225&quot;\/&gt;\n        &lt;\/group&gt;\n    &lt;\/section&gt;\n&lt;\/config&gt;<\/pre>\n\n\n\n<p>Now we will create a UpdateTotal.php file inside the model folder.<\/p>\n\n\n\n<p>You can simply use the below code in your UpdateTotal.php file and modify it accordingly. <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">namespace Webkul\\Test\\Model\\Total;\n\nclass UpdateTotal extends \\Magento\\Quote\\Model\\Quote\\Address\\Total\\AbstractTotal\n{\n\nprotected $quoteValidator = null;\n\n    public function __construct(\n    \\Magento\\Quote\\Model\\QuoteValidator $quoteValidator)\n    {\n    $this-&gt;quoteValidator = $quoteValidator; \n    }\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        if (&quot;You can define you condition here&quot;) {\n            $extraCharge = 10; \/\/ you can use your value\n            $total-&gt;setGrandTotal($total-&gt;getGrandTotal()+$extraCharge);\n            $total-&gt;setBaseGrandTotal($total-&gt;getBaseGrandTotal()+$extraCharge);\n        }else{\n            $total-&gt;setGrandTotal($total-&gt;getGrandTotal());\n            $total-&gt;setBaseGrandTotal($total-&gt;getBaseGrandTotal());  \n        }\n        return $this;\n        \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}<\/pre>\n\n\n\n<p>Now the Total will be updated based on your condition.<\/p>\n\n\n\n<p>That\u2019s all about on how to update the total on the <a href=\"https:\/\/store.webkul.com\/magento2-one-step-checkout.html\" target=\"_blank\" rel=\"noreferrer noopener\">checkout<\/a> page. Hope this will be helpful.<\/p>\n\n\n\n<p>This blog can be useful for various cart and payment-related operations including <a href=\"https:\/\/store.webkul.com\/magento2-partial-payment-emi.html\">Magento 2 partial payment.<\/a><\/p>\n\n\n\n<p>If you have any questions please comment below, and we will try to respond to you.<\/p>\n\n\n\n<p>Thanks for visiting the Webkul blog! \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Friends!! In today\u2019s blog, I will explain how we can modify the total on the checkout page. This blog is useful if you need to update the total based on any condition only on the checkout page. First of all, we will create a sales.xml file inside the, etc folder. You can simply use <a href=\"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":430,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9121],"tags":[14476,2460,14475],"class_list":["post-389556","post","type-post","status-publish","format-standard","hentry","category-magento-2","tag-customized-checkout-total-in-magento-2","tag-magento-2","tag-modify-total-on-the-checkout-page-in-magento-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Modify Total on the checkout page in Magento 2 - Webkul Blog<\/title>\n<meta name=\"description\" content=\"Modify Total on the checkout page in Magento 2, update total on checkout page based on any condition 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\/modify-total-on-the-checkout-page-in-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Modify Total on the checkout page in Magento 2 - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Modify Total on the checkout page in Magento 2, update total on checkout page based on any condition in magento 2\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/\" \/>\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=\"2023-07-04T11:53:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-18T09:33:44+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=\"Shweta Singh\" \/>\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=\"Shweta Singh\" \/>\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\/modify-total-on-the-checkout-page-in-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/\"},\"author\":{\"name\":\"Shweta Singh\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/2aa9e6c8f634365b94451ac7a636a444\"},\"headline\":\"Modify Total on the checkout page in Magento 2\",\"datePublished\":\"2023-07-04T11:53:47+00:00\",\"dateModified\":\"2023-07-18T09:33:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/\"},\"wordCount\":167,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"customized checkout total in magento 2\",\"Magento 2\",\"Modify Total on the checkout page in Magento 2\"],\"articleSection\":[\"Magento 2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/\",\"name\":\"Modify Total on the checkout page in Magento 2 - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2023-07-04T11:53:47+00:00\",\"dateModified\":\"2023-07-18T09:33:44+00:00\",\"description\":\"Modify Total on the checkout page in Magento 2, update total on checkout page based on any condition in magento 2\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Modify Total on the checkout page 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\/2aa9e6c8f634365b94451ac7a636a444\",\"name\":\"Shweta Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/51b8ea403cd7931cc8ef43d9b80e04e02143fd85bae4fe4ff866790408fb82d0?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\/51b8ea403cd7931cc8ef43d9b80e04e02143fd85bae4fe4ff866790408fb82d0?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Shweta Singh\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/shweta-singh342\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Modify Total on the checkout page in Magento 2 - Webkul Blog","description":"Modify Total on the checkout page in Magento 2, update total on checkout page based on any condition 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\/modify-total-on-the-checkout-page-in-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"Modify Total on the checkout page in Magento 2 - Webkul Blog","og_description":"Modify Total on the checkout page in Magento 2, update total on checkout page based on any condition in magento 2","og_url":"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2023-07-04T11:53:47+00:00","article_modified_time":"2023-07-18T09:33:44+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":"Shweta Singh","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Shweta Singh","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/"},"author":{"name":"Shweta Singh","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/2aa9e6c8f634365b94451ac7a636a444"},"headline":"Modify Total on the checkout page in Magento 2","datePublished":"2023-07-04T11:53:47+00:00","dateModified":"2023-07-18T09:33:44+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/"},"wordCount":167,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["customized checkout total in magento 2","Magento 2","Modify Total on the checkout page in Magento 2"],"articleSection":["Magento 2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/","url":"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/","name":"Modify Total on the checkout page in Magento 2 - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2023-07-04T11:53:47+00:00","dateModified":"2023-07-18T09:33:44+00:00","description":"Modify Total on the checkout page in Magento 2, update total on checkout page based on any condition in magento 2","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/modify-total-on-the-checkout-page-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Modify Total on the checkout page 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\/2aa9e6c8f634365b94451ac7a636a444","name":"Shweta Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/51b8ea403cd7931cc8ef43d9b80e04e02143fd85bae4fe4ff866790408fb82d0?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\/51b8ea403cd7931cc8ef43d9b80e04e02143fd85bae4fe4ff866790408fb82d0?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Shweta Singh"},"url":"https:\/\/webkul.com\/blog\/author\/shweta-singh342\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/389556","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\/430"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=389556"}],"version-history":[{"count":7,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/389556\/revisions"}],"predecessor-version":[{"id":391539,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/389556\/revisions\/391539"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=389556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=389556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=389556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}