Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_cart_calculate_fees', 'payment_fees' );
- function payment_fees ( $cart ) {
- if ( is_admin() && ! defined( 'DOING_AJAX' ) )
- return;
- $chosen_payment_id = WC()->session->get('chosen_payment_method');
- if ( empty( $chosen_payment_id ) )
- return;
- $subtotal = $cart->cart_contents_total + $cart->shipping_total ;
- // SETTINGS: Here set in the array the (payment Id) / (fee cost) pairs
- $targeted_payment_ids = array(
- 'ppcp-gateway' => ((6.5 * $subtotal / 100)+1)* 1.05 , // Percentage fee
- 'ppcp-card-button-gateway' => ((6.5 * $subtotal / 100)+1)* 1.05 , // Percentage fee
- 'stripe' => ((3.9 * $subtotal / 100)+1)* 1.05 , // Percentage fee
- 'cod' => ((3 * $subtotal / 100)+0.2)* 1.05 , // Percentage fee
- 'wallet' => ((2.9 * $subtotal / 100)+0.1)* 1.05 , // Percentage fee
- 'bacs' => ((2.99 * $subtotal / 100)+1)* 1.05 , // Percentage fee
- );
- // Loop through defined payment Ids array
- foreach ( $targeted_payment_ids as $payment_id => $fee_cost ) {
- if ( $chosen_payment_id === $payment_id ) {
- if ($payment_id === 'cod' || $payment_id === 'wallet') {
- $cart->add_fee( __('Handling & Service Fees', 'woocommerce'), $fee_cost, true );
- } else {
- $cart->add_fee( __('Payment Fees', 'woocommerce'), $fee_cost, true );
- }
- }
- }
- }
Advertisement
Comments
-
- If payment is COD or Wallet it shows Handling & Service Fees
- For other payment, it show Payment fees
Add Comment
Please, Sign In to add comment