Last active
June 4, 2020 11:39
-
-
Save karks88/415dde0eb580221269f67304e810eb4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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