• arazsalahli

    (@arazsalahli)


    Hi,

    I am using your plugin to add custom payment gateway to my website. I also want to apply discount (5%) to the total price hen this custom gateway is selected by the customer. I don’t know coding but I found a snippet in the forum which can be used for this purpose. The only problem is that I don’t know what is the payment id for your custom gateway. I know that the payment methods for Direct Bank Transfer, Cheque, Cash-on-Delivery and PayPal are bacs, cheque, cod and paypal respectively but not for this custom gateway.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter arazsalahli

    (@arazsalahli)

    Found that the ID of the custom payment gateway (created by free version of this plugin) is ‘alg_custom_gateway_1’and used below snippet to add 5% discount for this payment gateway.

    add_action( ‘woocommerce_cart_calculate_fees’,’ts_add_discount’, 20, 1 );

    function ts_add_discount( $cart_object ) {

    if ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) return;

    // Mention the payment method e.g. cod, bacs, cheque or paypal
    $payment_method = ‘alg_custom_gateway_1’;

    // The percentage to apply
    $percent = 5; // 5%

    $cart_total = $cart_object->subtotal_ex_tax;

    $chosen_payment_method = WC()->session->get(‘chosen_payment_method’); //Get the selected payment method

    if( $payment_method == $chosen_payment_method ){

    $label_text = __( “5% discount (Pay by bank card)” );

    // Calculating percentage
    $discount = number_format(($cart_total / 100) * $percent, 2);

    // Adding the discount
    $cart_object->add_fee( $label_text, -$discount, false );
    }
    }

    add_action( ‘woocommerce_review_order_before_payment’, ‘ts_refresh_payment_method’ );

    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
    }

    Thread Starter arazsalahli

    (@arazsalahli)

    Can you please also explain how I need to integrate the API settings, which is provided by bank as PHP file, into this ‘alg_custom_gateway_1’?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom payment gateway ID’ is closed to new replies.