Advertisement
borkolivic

Fee for COD

Aug 25th, 2020
2,081
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. add_action( 'woocommerce_cart_calculate_fees', 'mx_checkout_fee_for_cod' );
  2.  
  3. function mx_checkout_fee_for_cod() {
  4.     $chosen_gateway = WC()->session->get( 'chosen_payment_method' );
  5.     $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
  6.     $chosen_shipping = $chosen_methods[0];
  7.      if ( $chosen_gateway == 'cod' && 0 === strpos( $chosen_shipping, 'mx_local_shipping' )){
  8.       WC()->cart->add_fee( 'Naknada za plaćanje pouzećem', 0 );
  9.    }
  10.    else {
  11.         if ( $chosen_gateway == 'cod'){
  12.       WC()->cart->add_fee( 'Naknada za plaćanje pouzećem', 6 );
  13.     }
  14.     }
  15. }
  16.  
  17. add_action( 'woocommerce_review_order_before_payment', 'mx_refresh_checkout_on_payment_method_change' );
  18.  
  19. function mx_refresh_checkout_on_payment_method_change(){
  20.     ?>
  21.     <script type="text/javascript">
  22.         (function($){
  23.             $( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function() {
  24.                 $('body').trigger('update_checkout');
  25.             });
  26.         })(jQuery);
  27.     </script>
  28.     <?php
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement