Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Last active May 10, 2023 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpscholar/52f928563d23b50287e9f1c4d0f8494b to your computer and use it in GitHub Desktop.
Save wpscholar/52f928563d23b50287e9f1c4d0f8494b to your computer and use it in GitHub Desktop.
WooCommerce: Add a 4% Credit Card Processing Fee to the Checkout Page
<?php
/**
* WooCommerce Add Fee to the Checkout Page
*
* @package WooCommerceAddFeeToCheckout
* @author Micah Wood
* @copyright Copyright 2023 by Micah Wood - All rights reserved.
* @license GPL2.0-or-later
*
* @wordpress-plugin
* Plugin Name: WooCommerce Add Fee to the Checkout Page
* Plugin URI: https://gist.github.com/wpscholar/52f928563d23b50287e9f1c4d0f8494b
* Description: Add a fee to the WooCommerce checkout.
* Version: 1.0
* Requires PHP: 7.4
* Requires at least: 6.0
* Author: Micah Wood
* Author URI: https://wpscholar.com
* Text Domain: scratch-22
* Domain Path: /languages
* License: GPL V2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
add_action(
'woocommerce_cart_calculate_fees',
function () {
global $woocommerce;
$fee = ( $woocommerce->cart->cart_contents_total * 0.04 );
$woocommerce->cart->add_fee( 'Processing Fee', $fee );
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment