Home » Magento 2.0 Extensions » How to Add Custom Fee/Price in the Order Total in Magento 2?

How to Add Custom FeePrice to Order Total in Magento 2

How to Add Custom Fee/Price in the Order Total in Magento 2?

Adding custom fees to order totals in Magento 2 can be essential for covering additional costs like handling fees, customization charges, or special services. Third-party extensions offer an effective solution for those seeking a straightforward approach without diving into code. One such extension is the Extra Fee Extension by MageDelight, which provides a user-friendly way to manage and apply custom fees in your Magento store.

The Role of Custom Fees in eCommerce

Custom fees are a powerful tool for eCommerce businesses, allowing them to manage and allocate costs beyond the introductory product price. By implementing custom fees, online merchants can ensure that all expenses associated with the sale are appropriately covered and offer additional services that enhance the shopping experience.

Cover Additional Costs

One of the primary roles of custom fees is to cover additional costs that may arise during the sales process. These costs could include handling charges, processing fees, or other operational expenses not factored into the product’s base price. For instance, some products may require special packaging or specific orders must be processed more quickly. By adding custom fees, businesses can ensure these extra costs do not affect their profit margins. This approach also allows businesses to be transparent with customers about the reasons behind additional charges, fostering trust and clarity.

Offer Premium Options

Custom fees also enable businesses to offer premium services to their customers. For example, customers might want their purchases gift-wrapped or need expedited shipping to receive their orders sooner. These value-added services go beyond the standard offerings and come with their costs. Custom fees provide a way to charge customers for these premium options, allowing businesses to cater to different customer needs and preferences without compromising quality or profitability. By offering such options, businesses can enhance the overall customer experience and potentially increase customer satisfaction and loyalty.

Implement Business Rules

Custom fees can be configured based on specific business rules, allowing for a more tailored pricing and cost management approach. For example, businesses can set up fees based on the order amount, where higher-value orders might incur different fees than lower-value ones. Similarly, fees can be applied based on customer groups, rewarding loyal customers with lower fees or charging different rates to wholesale buyers versus retail customers. This flexibility enables businesses to align their pricing strategies with their overall business goals, whether encouraging larger purchases, promoting loyalty programs, or managing the costs associated with different types of customers.

Steps to to Add Custom Price/fee in Order total in Magento 2

Step 1. First, you need to create a sales.module in the folder, then run the following command:

<?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="extrafee" instance="Magedelight\Test\Model\Total\Extrafee" sort_order="150"/>

</group>  

</section>

</config>

Step 2. Then define app\code\Magedelight\Test\Model\Total\Customfee.php to update the total fees and follow the below code:

class Extrafee 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->getextrafee(); 

     $extrafee = 100; //enter amount which you want to set

     $balance = $extrafee - $exist_amount;//final amount

 

     $total->setTotalAmount('extrafee', $balance);

     $total->setBaseTotalAmount('extrafee', $balance);

 

     $total->setExtrafee($balance);

     $total->setBaseExtrafee($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' => 'extrafee',

         'title' => 'Extra Fee',

         'value' => 100

     ];

}

/**

  * Get Subtotal label

  *

  * @return \Magento\Framework\Phrase

  */

public function getLabel()

{

     return __('Extra Fee');

}

}

To view the step-by-step installation process for the MageDelight Extra Fee Extension, click here.

Advantages of Using MageDelight’s Extra Fee Extension

While custom fees are invaluable, implementation can sometimes be complex, especially when managing multiple fees with varying conditions. This is where MageDelight’s Extra Fee Extension for Magento 2 comes into play. This extension simplifies adding and managing custom fees, offering a range of features that make it a must-have for Magento 2 store owners.

Ease of Use

MageDelight’s Extra Fee Extension is designed with user-friendliness in mind. The extension offers an intuitive admin panel that allows merchants to configure custom fees without the need for any coding skills. This ease of use ensures that even those with limited technical knowledge can effectively manage their store’s pricing strategy. The graphical interface provides clear options and settings, making adding custom fees straightforward and efficient.

Flexible Configuration

One of the standout features of the MageDelight Extra Fee Extension is its flexible configuration options. Store owners can set up multiple fees based on various conditions, such as order totals, customer groups, or shipping methods. This flexibility allows businesses to create a pricing structure aligned with their needs and objectives. For example, different fees can be applied to different shipping methods, ensuring that the cost of more expensive shipping options is covered. Similarly, businesses can create special fees for specific customer groups, such as offering discounts or additional charges depending on the customer’s status.

Seamless Integration

Integration is critical when adding any new feature to an eCommerce store. MageDelight’s Extra Fee Extension integrates seamlessly with Magento’s existing checkout and invoicing systems. This ensures that all custom fees are applied correctly and consistently throughout the customer’s shopping journey, from adding products to the cart to completing the purchase. The seamless integration also means no disruptions to the user experience, which is essential for maintaining customer satisfaction.

Key Features of Extra Fees Magento 2 Extension by MageDelight

Flexible Surplus Fees for Additional Services

The Extra Fee Extension for Magento 2 allows merchants to create flexible surplus fees for additional services offered to customers. This feature is handy for businesses that provide optional services like gift wrapping, faster shipping, or personalized packaging. With this extension, you can set up fees that reflect the cost of these services, ensuring that customers are only charged for the extras they choose. This flexibility enhances the shopping experience by offering more options and helps maintain transparent pricing. Customers appreciate knowing exactly what they are paying for and the ability to opt in or out of additional services per their needs.

Attribute-Based Extra Fees

The extension’s ability to apply extra fees based on various attributes is a powerful tool for creating a dynamic pricing structure. Attributes could include anything from the customer’s shipping method, order total, or selected payment method to specific product categories or customer groups. For instance, you might want to charge a fee for international shipping or offer a discount on fees for loyal customers. This feature allows you to tailor fees precisely, ensuring they are applied only when relevant conditions are met. By aligning fees with specific attributes, you can better manage costs and offer a pricing strategy that meets the unique needs of different customer segments.

Global Fee Configuration for Consistent Application

The Global Settings feature allows you to configure fees that will apply across all products in your store. This is ideal for fees that need to be universally applied, such as environmental fees, regulatory surcharges, or handling fees. By setting these fees globally, you ensure consistency and avoid the need to configure the same fee multiple times for different products or categories. This saves time and ensures that all customers are subject to the same rules, reducing the risk of errors or omissions. The global configuration is crucial for businesses to streamline their fee management process while maintaining clarity and fairness across all transactions.

Unlimited Extra Fee Rules

With the Extra Fee Extension, you can create unlimited extra fee rules, giving you the flexibility to manage various scenarios. Whether you need to apply different fees based on customer location, order value, or product type, this feature allows you to set up as many rules as necessary. The ability to create unlimited rules ensures that you can manage your pricing structure effectively, no matter how complex your pricing structure is. This flexibility is precious for businesses with diverse product ranges or customer bases, as it allows for precise control over how and when fees are applied.

Front-End Display of Extra Fees

Transparency is critical to maintaining customer trust, and the Extra Fee Extension ensures that all extra fees are explicitly displayed on the front end of your store. This means that customers can see additional charges before they complete their purchase, reducing the likelihood of surprise fees that could lead to cart abandonment or dissatisfaction. The clear display of fees during checkout ensures that customers are fully informed, which is crucial for maintaining a positive shopping experience and building long-term loyalty.

Sorting and Prioritizing Extra Fee Rules

Another valuable feature of the Extra Fee Extension is the ability to sort and prioritize extra fee rules. This allows you to control the order in which fees are applied, ensuring that the most relevant fees are prioritized during checkout. Depending on your business model, you should prioritize shipping overpayment method fees. By sorting fees according to your needs, you can optimize the checkout process, making it smoother and more intuitive for customers.

Enabling Fees for Both Customers and Admins

The extension also allows fees to be enabled for both customers and admins. This means that while customers see and pay the extra fees on the front end, admins can also view and manage these fees on the back end. This dual visibility ensures that all parties are aware of the fees. It also allows admins to make necessary adjustments, manage exceptions, or apply fees manually when required. This feature is essential for maintaining a seamless flow of information between the customer-facing side of your store and the back-end operations.

Mandatory Extra Fees for All Transactions

Finally, the Extra Fee Extension allows adding mandatory fees for admins and customers. This feature ensures that specific fees are always applied, regardless of other conditions. Mandatory fees include recycling fees, regulatory charges, or compulsory service fees. By making these fees mandatory, you ensure compliance with legal requirements or internal policies and guarantee that all customers contribute to necessary costs. This consistency is vital to maintaining a fair and transparent pricing model, benefiting your business and customers.

Benefits of Implementing Custom Fees

Custom fees can benefit Magento 2 stores when implemented effectively, enhancing operational efficiency and customer satisfaction.

Transparency
One of the primary benefits of custom fees is communicating additional charges to customers. By using the Extra Fee Extension’s display and invoice features, merchants can ensure that all fees are transparent, reducing the likelihood of disputes or confusion. Transparency in pricing builds customer trust, essential for long-term loyalty and positive word-of-mouth.

Flexibility
The Extra Fee Extension provides great flexibility, allowing merchants to adjust fees quickly based on changing business requirements or promotional activities. For instance, during peak seasons, a store might implement a rush fee for expedited orders or offer discounted fees to loyalty program members as part of a special promotion. This adaptability helps businesses remain agile and responsive to market demands.

Enhanced Revenue Management
Finally, custom fees can play a crucial role in enhanced revenue management. By capturing additional revenue for services or costs not covered by the standard product price, businesses can protect their profit margins and ensure that all operational expenses are accounted for. This is particularly important in industries with thin margins or where additional services significantly affect customer satisfaction.

Conclusion

Adding a custom fee or price to the order total in Magento 2 is a valuable capability that allows you to fine-tune your pricing strategy to reflect better the services and costs associated with your products. Following the steps outlined, you can easily implement custom fees communicated to your customers, ensuring transparency and trust throughout the shopping experience. Whether you need to account for additional services, specific shipping methods, or any other unique business requirement, Magento 2 provides the flexibility to manage these fees efficiently. This customization helps cover additional costs and enhances your store’s overall functionality, contributing to a smoother checkout process and improved customer satisfaction.

Tags

Tanya

Tanya

A passionate writer and an avid explorer of ideas. With love for words and curiosity that knows no bounds, she has embarked on a journey of sharing her thoughts, insights, and experiences through the power of blogging. Her knowledge is the logarithmic result of her years of experience.