How to Add a surcharge with WooCommerce: If you are a WooCommerce user this great snippet will add a 1% surcharge to your cart on checkout.
You can easily change the $percentage variable to adjust the surcharge percent and you are good to go.
How to Add a surcharge with WooCommerce. Add code to your child theme’s functions.php
file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Avoid adding custom code directly to your parent theme’s functions.php
file as this will be wiped entirely when you update the theme.
/** * Add a 1% surcharge to your cart / checkout * change the $percentage to set the surcharge to a value to suit */ add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' ); function woocommerce_custom_surcharge() { global $woocommerce; if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $percentage = 0.01; $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage; $woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' ); }
( WordPress codex functions, hooks, in this snippet: )
Related Videos:
Related Posts:
How to Define a percent surcharge by delivery country with WooCommerce
How to Update: Automatically create media_buttons for shortcode selection
Create a PayPal Donation Shortcode – WordPress
Using the Current Year in Your Posts – WordPress
What is the use of New Keyword in VB.NET?
Change the Author Permalink Structure
How To Start a Blog – Beginner’s Guide for 2020
What is a Shortcode in WordPress?
The background-color CSS property
What is the Python Software Foundation?
Python 3 Object Oriented Programming
B0r0nt0K Ransomware Wants $75,000 Ransom, Infects Linux Servers
Are there copyright restrictions on the use of Python?
How to Spy on Competitors with Python & Data Studio
Kodi-04-2019 No Limits Wizard Magic Build for Kodi 18 Leia
Windows 10 Activator Key, Activate Windows 10 with a batch file