• Resolved wino97

    (@wino97)


    Hello,
    I am working on simple addon to wordpress.
    I have made my own payment gateway which uses “user balance”.
    How can i check if user has sufficient amount of credits to use them in current order.
    If user hasn’t enough then he shouldn’t be able to proceed with this payment method.
    I got current balance and order value, but i don’t know how prevent placing order.
    Regards.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You can use the woocommerce_available_payment_gateways filter:

    function remove_payment_method_if_not( $available_gateways ) {
    
    // check your condition
    
    if ( true == $my_condition ) {
        unset( $available_gateways['my-gateway'] );
    }
    return $available_gateways;
    }
    
    add_filter( 'woocommerce_available_payment_gateways', 'remove_payment_method_if_not', 10, 1 );
    Thread Starter wino97

    (@wino97)

    Thanks, maybe not what i was looking for, but makes job done.

    If you don’t want to remove the method, just block the order placement, you can go with the woocommerce_checkout_process hook, and add an error message:

    add_action( 'woocommerce_checkout_process', 'dont_allow_order', 10 );
     
    function dont_allow_order() {
    
    // check your condition
    
    if ( true == $my_condition ) {
       if( is_checkout() ) {
           wc_print_notice( sprintf( 'You don't have enough credits.' ), 'error' );
           }
       }
    
    }
    Thread Starter wino97

    (@wino97)

    How can I change suggested payment method.
    On the image below you can see that my payment method is grayed out.
    FV

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Check before placing order’ is closed to new replies.