如何在Woocommerce中获取付款方式的ID?

huangapple go评论68阅读模式
英文:

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( &#39;woocommerce_available_payment_gateways&#39;, &#39;custom_paypal_disable_manager&#39; );
function custom_paypal_disable_manager( $available_gateways ) {
   if ( $total_amount &lt; 3000 ) {
      unset( $available_gateways[&#39;ID payment gateway&#39;] );
   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( &#39;woocommerce_gateway_title&#39;, &#39;display_payment_method_id_for_admins_on_checkout&#39;, 100, 2 );
function display_payment_method_id_for_admins_on_checkout( $title, $payment_id ){
 	if( is_checkout() &amp;&amp; ( current_user_can( &#39;administrator&#39;) || current_user_can( &#39;shop_manager&#39;) ) ) {
		$title .= &#39; &lt;code style=&quot;border:solid 1px #ccc;padding:2px 5px;color:red;&quot;&gt;&#39; . $payment_id . &#39;&lt;/code&gt;&#39;;
 	}
 	return $title;
}

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

如何在Woocommerce中获取付款方式的ID?

答案2

得分: 1

你应该能够在你的浏览器开发工具中获取这些ID,我相信。对我来说,上面的代码显示的值与我在代码中看到的值完全相同。
如何在Woocommerce中获取付款方式的ID?

英文:

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.
如何在Woocommerce中获取付款方式的ID?

huangapple
  • 本文由 发表于 2023年7月3日 21:23:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76605181.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定