How to Set Extra Fixed Price For Stripe Payment Gateway via Custom PHP Code in WooCommerce Checkout

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • In this woocommerce tutorial for beginners you will learn how to set additional charges / fees on stripe payment gateway if customer / user select stripe in checkout page using custom php snippet in wordpress website. So when person select payment method on checkout then additional flat fee / amount /apply on whole cart total price.
    * Find Code in Top Pinned Comment Section.
    * In code you can add stripe credit card payment gateway id.
    Use this css:
    .custom-stripe-fee {
    padding: 2px 8px;
    border-radius: 2px;
    margin-left: 10px;
    background-color: #dfdbdb;
    float: right;
    font-size: 12px;
    }
    #woocommerce #stripe #paymentgateway #paymentmethod #price #fee #fees #checkout #wordpress #wordpresstutorial #wordpresstutorialforbeginners #webtaskwithhassan #hassangilani

КОМЕНТАРІ • 3

  • @WebTaskWithHassan
    @WebTaskWithHassan  Рік тому

    Use this code:
    // Create Additional Fixed Fee for a Stripe Payment Gateway
    add_action( 'woocommerce_cart_calculate_fees', 'wtwh_stripe_fee', 25 );
    function wtwh_stripe_fee( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
    return;
    }
    // if "Stripe" is the selected payment method, we add the fee
    if( 'stripe' == WC()->session->get( 'chosen_payment_method' ) ) {
    WC()->cart->add_fee( 'Additional / Fixed Stripe Fee', 10 );
    // you can also use: $cart->add_fee( 'Additional PayPal Fee',10 );
    }
    }
    // Refresh the Checkout on Payment Method Change
    add_action( 'woocommerce_checkout_init', 'wtwh_checkout_refresh' );
    function wtwh_checkout_refresh() {
    wc_enqueue_js( "jQuery( function( $ ){
    $( 'form.checkout' ).on( 'change', 'input[name^=\"payment_method\"]', function(){
    $( 'body' ).trigger( 'update_checkout' );
    });
    });");
    }
    // Display Fee Amount Next to Payment Method Title
    add_filter( 'woocommerce_gateway_icon', 'wtwh_display_method_fee', 25, 2 );
    function wtwh_display_method_fee( $icon_html, $gateway_id ) {
    if( 'stripe' === $gateway_id ) {
    return '' . wc_price( 10 ) . '';
    }
    else {
    return $icon_html;
    }
    }
    -------------------
    CSS:
    .custom-stripe-fee {
    padding: 2px 8px;
    border-radius: 2px;
    margin-left: 10px;
    background-color: #dfdbdb;
    float: right;
    font-size: 12px;
    }

    • @siinxx7656
      @siinxx7656 10 місяців тому

      This worked perfectly!! Wow! Thank you so much. I'm only having some trouble by trying to changed the fixed value to a %, let's say 10% of the total of the product. That's how in my case Stripe charges their fee.

    • @WebTaskWithHassan
      @WebTaskWithHassan  10 місяців тому

      ​@@siinxx7656 checkout this video to add additional charges in percentage amount for order amount using plugin for stripe payment gateway..
      ua-cam.com/video/zqELLBPz73E/v-deo.html