mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
https://docs.woocommerce.com/document/add-a-surcharge-to-cart-and-checkout-uses-fees-api/
12 lines
407 B
Text
12 lines
407 B
Text
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
|
|
function woocommerce_custom_surcharge() {
|
|
global $woocommerce;
|
|
|
|
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
|
|
return;
|
|
|
|
$percentage = 0.03;
|
|
$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
|
|
$woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' );
|
|
|
|
}
|