Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wbcomdev/7608f9dbfa4005ccf929a7c0c7da28ce to your computer and use it in GitHub Desktop.

Select an option

Save wbcomdev/7608f9dbfa4005ccf929a7c0c7da28ce to your computer and use it in GitHub Desktop.
/**
* Add a 1% surcharge to your cart / checkout.
* change the $percentage to set the surcharge to a value to suit.
*/
function wb_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, '' );
}
add_action( 'woocommerce_cart_calculate_fees', 'wb_woocommerce_custom_surcharge' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment