1

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.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Stan Law
  • 61
  • 6

2 Answers2

2

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

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • @LoicTheAztec, "Once used, remove it." If we don't comment or delete the code you wrote after using it, will there be a security problem? If only I am the admin! – Adam Luper Jul 20 '23 at 14:16
  • 1
    @AdamLuper you can just comment the `add_filte('… …);`line, to disable it. – LoicTheAztec Jul 20 '23 at 16:20
1

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

mwlandof
  • 39
  • 4