选择付款方式(信用卡)时,如何在总金额中添加百分比?
例如:如果客户货到付款,那么底价,如果我选择在线支付,那么我收取的百分比加到总金额中?
货到付款的网关 ID 设置为:cod 在线支付的网关 ID 设置为:tinkoff
add_action( 'woocommerce_after_calculate_totals', 'custom_fee_for_tinkoff' );
function custom_fee_for_tinkoff( $cart ) {
if ( is_checkout() || defined('WOOCOMMERCE_CHECKOUT') ) {
$payment_method = WC()->session->get( 'chosen_payment_method' );
if ($payment_method == 'tinkoff') {
$percentage = 0.025;
$surcharge = ( $cart->cart_contents_total + $cart->tax_total ) * $percentage;
$cart->add_fee( 'Комиссия банка', $surcharge, true, '' );
}
else { return; }
}
}