add_action( 'woocommerce_cart_calculate_fees','wbmz_add_discount', 20, 1 );
function wbmz_add_discount( $cart_object ) {  if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
  // voeg toe bij alles BEHALVE op rekening ALLEEN VOOR WINKELIERS

  $payment_method = 'cheque';
  // The percentage to apply
  $percent = 4; // 2%
  $cart_total = $cart_object->subtotal_ex_tax;
  $chosen_payment_method = WC()->session->get('chosen_payment_method'); // Krijg de betaalmethode

  if( $payment_method != $chosen_payment_method && current_user_can('winkelier') || $payment_method != $chosen_payment_method && current_user_can('administrator-not') ){
    $label_text = __( "4% Direct betalen korting", "wbmz" );
    // percentage berekenen
    $discount = number_format(($cart_total / 100) * $percent, 2);

    // Korting toevoegen
    $cart_object->add_fee( $label_text, -$discount, false );
  }
}

add_action( 'woocommerce_review_order_before_payment', 'ts_refresh_payment_method' );
// Refresh de winkelwagen als de actie wordt uitgevoerd
function ts_refresh_payment_method(){ // jQuery ?>
  <script type="text/javascript">
    (function($){ $( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function() {
      $('body').trigger('update_checkout');
    });
  })(jQuery);
</script>
<?php }
Geef een reactie 0