skip to Main Content

Maybe someone knows, how to add a condition: if the payment amount is less than 3000 – certain payment method is hidden?

For example, there are 2 payment methods:

  • cash
  • online payment

If the amount is less than 3000, the "cash" method is hidden.

As far as I understand, I need to get the payment gateway ID, and then apply the snippet:

add_filter( 'woocommerce_available_payment_gateways', 'custom_paypal_disable_manager' );
function custom_paypal_disable_manager( $available_gateways ) {
   if ( $total_amount < 3000 ) {
      unset( $available_gateways['ID payment gateway'] );
   return $available_gateways;
}

But I don’t know how to get the payment gateway ID (there are several payment methods and they are all implemented by different plugins).
Perhaps there is a way to get all IDs of payment gateways in a list.

I would be grateful for any information.

2

Answers


  1. Get the payment method ID in WooCommerce Checkout page

    Using the following code, will display on checkout payment methods, the payment ID visible only to the admins:

    add_filter( 'woocommerce_gateway_title', 'display_payment_method_id_for_admins_on_checkout', 100, 2 );
    function display_payment_method_id_for_admins_on_checkout( $title, $payment_id ){
        if( is_checkout() && ( current_user_can( 'administrator') || current_user_can( 'shop_manager') ) ) {
            $title .= ' <code style="border:solid 1px #ccc;padding:2px 5px;color:red;">' . $payment_id . '</code>';
        }
        return $title;
    }
    

    Code goes in functions.php file of your active child theme (or active theme).
    Once used, remove it.

    enter image description here

    Login or Signup to reply.
  2. You should be able to get the IDs with Developer Tools in your browser I believe. For me, code above shows exactly the same values I can see in code.
    LEFT: Payment id with a code; RIGHT: IDs marked red in devtools

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search