Skip to content

Instantly share code, notes, and snippets.

@karks88
Last active June 4, 2020 11:39
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 karks88/415dde0eb580221269f67304e810eb4d to your computer and use it in GitHub Desktop.
Save karks88/415dde0eb580221269f67304e810eb4d to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: WooCommerce Order Surcharge
Plugin URI: https://www.karks.com
Description: Adds a flat surcharge to every order. Based on WooCommerce Snippet: https://docs.woocommerce.com/document/add-a-surcharge-to-cart-and-checkout-uses-fees-api/
Version: 1.0
Author: Eric Karkovack
Author URI: https://www.karks.com
Code culled from https://docs.woocommerce.com/document/add-a-surcharge-to-cart-and-checkout-uses-fees-api/
*/
/**
* Add a standard $ value surcharge to all transactions in cart / checkout
*/
add_action( 'woocommerce_cart_calculate_fees','wc_add_surcharge' );
function wc_add_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$county = array('US');
// change the $fee to set the surcharge to a value to suit
$fee = 1.00;
if ( in_array( WC()->customer->get_shipping_country(), $county ) ) :
$woocommerce->cart->add_fee( 'Processing Fee', $fee, true, 'standard' );
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment