Cookies setting

Cookies help us enhance your experience on our site by storing information about your preferences and interactions. You can customize your cookie settings by choosing which cookies to allow. Please note that disabling certain cookies might impact the functionality and features of our services, such as personalized content and suggestions. Cookie Policy

Cookie Policy
Essential cookies

These cookies are strictly necessary for the site to work and may not be disabled.

Information
Always enabled
Advertising cookies

Advertising cookies deliver ads relevant to your interests, limit ad frequency, and measure ad effectiveness.

Information
Analytics cookies

Analytics cookies collect information and report website usage statistics without personally identifying individual visitors to Google.

Information
mageplaza.com

How to configure Extra Fee in Magento 2

Vinh Jacker | 3 days ago

How to configure Extra Fee in Magento 2 How to configure Extra Fee in Magento 2

The Most Popular Extension Builder for Magento 2

With a big catalog of 224+ extensions for your online store

The Magento 2 extra fee extension enables e-commerce businesses to apply additional charges for services like expedited shipping, gift wrapping, installation fees, and more.

If you want to add extra fees at checkout in Magento 2, this article provides two solutions: adding custom charges through code or using third-party extensions.

Why Need to Add Extra Fee at Magento Checkout?

add-extra-fee-at-magento-checkout

Adding extra charges is a valuable feature for store owners who offer additional services, such as one-day delivery or gift wrapping. However, Magento only supports a few default fees, like free shipping or flat rates, often leading store owners to include these charges in product prices.

This approach has two significant drawbacks:

  • Customers may not be aware of the additional costs
  • It can significantly raise product prices, increasing the likelihood of shopping cart abandonment.

The Magento 2 Add Extra Fee in Checkout feature addresses these issues by allowing store owners to add extra fees during checkout, making customers more aware of them. It also displays these fees on the storefront when items are added to the cart, enhancing the shopping experience.

2 Methods to Add Extra Fee at Checkout in Magento 2

Method 1: Add Extra Fee Programmatically

If you have coding experience and prefer a free solution, you can customize Magento 2 to add an extra fee at checkout by following these steps:

Step 1: Create a new file named sales.xml in the etc folder of your Magento module.

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/sales.xsd">
    <section name="quote">
        <group name="totals">
            <item name="customfee" instance="Webkul\Test\Model\Total\Customfee" sort_order="150"/>
        </group>  
    </section>
</config>

Step 2: Create the Customfee.php file within the app/code/Webkul/Test/Model/Total directory.

This file will contain the PHP code that calculates and applies the extra fee to the order total.

Step 3: Update the total according to custom fee

In this step, you’ll set up your Magento configuration to automatically update the order total based on your defined extra fee.

class Customfee extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
{
   /**
     * Collect grand total address amount
     *
     * @param \Magento\Quote\Model\Quote $quote
     * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
     * @param \Magento\Quote\Model\Quote\Address\Total $total
     * @return $this
     */
    protected $quoteValidator = null; 

    public function __construct(\Magento\Quote\Model\QuoteValidator $quoteValidator)
    {
        $this->quoteValidator = $quoteValidator;
    }
  public function collect(
        \Magento\Quote\Model\Quote $quote,        \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
        \Magento\Quote\Model\Quote\Address\Total $total
    ) {
        parent::collect($quote, $shippingAssignment, $total);


        $exist_amount = 0; //$quote->getCustomfee(); 
        $customfee = 100; //enter amount which you want to set
        $balance = $customfee - $exist_amount;//final amount

        $total->setTotalAmount('customfee', $balance);
        $total->setBaseTotalAmount('customfee', $balance);

        $total->setCustomfee($balance);
        $total->setBaseCustomfee($balance);

        $total->setGrandTotal($total->getGrandTotal() + $balance);
        $total->setBaseGrandTotal($total->getBaseGrandTotal() + $balance);


        return $this;
    } 

    protected function clearValues(Address\Total $total)
    {
        $total->setTotalAmount('subtotal', 0);
        $total->setBaseTotalAmount('subtotal', 0);
        $total->setTotalAmount('tax', 0);
        $total->setBaseTotalAmount('tax', 0);
        $total->setTotalAmount('discount_tax_compensation', 0);
        $total->setBaseTotalAmount('discount_tax_compensation', 0);
        $total->setTotalAmount('shipping_discount_tax_compensation', 0);
        $total->setBaseTotalAmount('shipping_discount_tax_compensation', 0);
        $total->setSubtotalInclTax(0);
        $total->setBaseSubtotalInclTax(0);
    }
    /**
     * @param \Magento\Quote\Model\Quote $quote
     * @param Address\Total $total
     * @return array|null
     */
    /**
     * Assign subtotal amount and label to address object
     *
     * @param \Magento\Quote\Model\Quote $quote
     * @param Address\Total $total
     * @return array
     */
    public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
    {
        return [
            'code' => 'customfee',
            'title' => 'Custom Fee',
            'value' => 100
        ];
    }

    /**
     * Get Subtotal label
     *
     * @return \Magento\Framework\Phrase
     */
    public function getLabel()
    {
        return __('Custom Fee');
    }
}

Following these two simple steps, you’ve successfully added a custom fee to your Magento 2 checkout page.

Method 2: Add Extra Fee using Magento 2 Extension

If you don’t have coding experience, using a third-party extension is best. Fortunately, several Magento eCommerce extensions can help you add custom fees to the checkout process. Now, we will guide you on how to add an extra fee with the Extra Fee extension by Mageplaza in a very simple way.


Extra fee

Extra Fee for Magento 2

Diversify extra services to your Magento 2 checkout page with the Extra Fee extension

Check it out!


Step 1: Enter the full information in the General section

  • Navigate to Mageplaza > Extra Fee > Manage Rules > Add New Rule

enter-full-information-1

  • Name: Enter a descriptive name for this extra fee rule.
  • Status: Select “Enabled” to activate this rule and apply the extra fee to orders.
  • Description: Provide a brief explanation of the extra fee, such as its purpose or the criteria for applying it.
  • Store Views: Choose which specific stores should have this extra fee applied. You can select multiple stores.

enter-full-information-2

  • Customer Groups: Determine which customer groups will see this extra fee. You can select multiple groups.
  • Priority: Set the order in which this rule should be applied if multiple rules are active. A higher priority means the rule will be applied first.
  • Message title: Enter messages/ reason for this extra fee
  • Allow customers notes: Select yes to show the message section

Step 2: Enter the full information in the Condition section

step2

Here, you can customize the conditions for different sections like Cart, Product, Customer, and more. For example, you can set rules based on the total amount spent, the number of items in the cart, product availability, customer details, and other factors.

Sep 3. Enter information in the Action section

step3

There are 2 options to choose Apply Type: Automatic and Manual.

Option 1: Apply Type = Automatic

  • Apply for: If you choose Each Product in Cart instead of Whole Cart, you need to enter the conditions based on product attributes like color, climate, and category.

step2-option1

  • Fee Type: Choose the service Fee Type

Percentage of Cart Total: The fee will be a percentage of the total cart value. Fixed Amount for the Whole Cart: The fee will be a fixed amount applied to the entire cart when customers make a purchase. Fixed Amount for Each Item: The fee will be a fixed amount applied to each item in the cart.

  • Amount: Enter the amount or percentage based on the payment type you select

  • Enter the remaining fields: Tax, sort order, and refundable.

Option 2: Apply Type = Manual

  • Apply for: Configure similar to the Automatic option

  • Display Area: There are three options to choose from: Payment Method, Shipping Method, and Cart Summary.

  • Display type:

Checkbox: Allows a user to choose one or more options from a list of fees. Each option can be chosen independently or deselected. Radio: Allows customers to select only one option from a list of fees. Once an option is selected, the other options become deselected.

  • Configure the remaining fields in a way that is similar to the Automatic Option.

Step 4. Config Label & Options (for Apply Type = Manual)

config-label-options

Unlike the automatic option, with the manual option, you need to configure the Manage Label and Options section.

  • Click “Add option” to add unlimited fees and enter all needed information for each fee type.
  • Click “Save” to finish.

Congratulations! You have completed all steps to add an extra fee.

Final Words

To provide the most relevant advice, please share more details about the extra fee you want to add. Specifically, please indicate the nature of the fee, the conditions under which it should be applied, any existing Magento customizations or extensions that might influence the implementation, and your level of technical familiarity with Magento. This information will help me tailor my response to your unique needs.

Table of content
    Jacker

    With over a decade of experience crafting innovative tech solutions for ecommerce businesses built on Magento, Jacker is the mastermind behind our secure and well-functioned extensions. With his expertise in building user-friendly interfaces and robust back-end systems, Mageplaza was able to deliver exceptional Magento solutions and services for over 122K+ customers around the world.



    Related Post

    Website Support
    & Maintenance Services

    Make sure your store is not only in good shape but also thriving with a professional team yet at an affordable price.

    Get Started
    mageplaza services