Advertisement
borkolivic

Add checkout fee for shipping/payment method combination

Dec 17th, 2019
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. // Add fee for specific shipping/payment method combo
  2.  
  3. add_action( 'woocommerce_cart_calculate_fees', 'mx_add_fee_to_checkout' );
  4.  
  5. function mx_add_fee_to_checkout() {
  6.     $chosen_gateway = WC()->session->get( 'chosen_payment_method' );
  7.     $chosen_methods = WC()->session->get( 'chosen_shipping_methods');
  8.     $chosen_shipping = $chosen_methods[0];
  9.        if ( ($chosen_gateway == 'cod') &&  0 === strpos($chosen_shipping, 'flat_rate:2')) {
  10.           WC()->cart->add_fee( 'Extra Fee for COD & Flat rate', 5 );
  11.       }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement