英文:
How to get the ID of a payment method in Woocommerce?
问题
也许有人知道,如何添加一个条件:如果支付金额低于3000 - 则隐藏特定的支付方式?
例如,有2种支付方式:
- 现金
- 在线支付
如果金额低于3000,将隐藏“现金”支付方式。
据我所了解,我需要获取支付网关的ID,然后应用以下代码段:
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'] );
return $available_gateways;
}
但我不知道如何获取支付网关的ID(有几种支付方式,它们都是由不同的插件实现的)。
也许有一种方法可以将所有支付网关的ID都列出来。
我会对任何信息表示感激。
英文:
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.
答案1
得分: 2
使用以下代码,在WooCommerce结账页面上显示付款方式ID,仅对管理员可见:
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;
}
将此代码放在您的活动子主题(或活动主题)的functions.php文件中。
使用后,请删除它。
英文:
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). <br>Once used, remove it.
答案2
得分: 1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论