This PHP code adds a percentage of your total after the checkout total without affecting the totals. This way you can show your customer how much of the total you donated to charity without the amount affecting the donation amount your customer pays at the checkout.
The solution is based on the subtotal before taxes and shipping costs so only affects the total of your products and not any additional fees, taxes or charges.
In this example, 2 seperate products are purchased totaling $200 and 80% is donated equalling a total donation of $160. The donation percentage is excluded from the extra shipping fee.
The code updates dynamically based on the cart and checkout page subtotals adding the amount to the checkout order totals table as seen above.
Add the code to the end of your child themes functions file or custom functions plugin for PHP code snippets.
To modify the donation text and percentage, go to :
- Line 11, swap out the percentage.
- Line 19, swap out the donation text.