如何为 WooCommerce 中的未登录用户禁用特定插件?
How to disable a specific plugin for unlogged users in WooCommerce?
我正在尝试为未登录的用户禁用 WooCommerce PayPal Checkout Payment Gateway。我该怎么做?
已更新 - 以下内容将为未登录的用户禁用 Paypal Checkout 支付网关:
add_filter( 'woocommerce_available_payment_gateways', 'conditionally_disable_paypal_payment_gateways', 10, 1 );
function conditionally_disable_paypal_payment_gateways( $available_gateways ) {
if ( is_admin() ) return $available_gateways; // Only on frontend
// Loop through payment gateways
foreach( $available_gateways as $gateways_id => $gateways ){
if ( ! is_user_logged_in() && $gateways_id === 'ppec_paypal' ) {
unset($available_gateways[$gateways_id]);
}
}
return $available_gateways;
}
代码进入您的活动子主题(或活动主题)的 functions.php 文件。已测试并有效。
For Woocommerce default Paypal payment gateway, replace 'ppec_paypal'
by 'paypal'
.
我正在尝试为未登录的用户禁用 WooCommerce PayPal Checkout Payment Gateway。我该怎么做?
已更新 - 以下内容将为未登录的用户禁用 Paypal Checkout 支付网关:
add_filter( 'woocommerce_available_payment_gateways', 'conditionally_disable_paypal_payment_gateways', 10, 1 );
function conditionally_disable_paypal_payment_gateways( $available_gateways ) {
if ( is_admin() ) return $available_gateways; // Only on frontend
// Loop through payment gateways
foreach( $available_gateways as $gateways_id => $gateways ){
if ( ! is_user_logged_in() && $gateways_id === 'ppec_paypal' ) {
unset($available_gateways[$gateways_id]);
}
}
return $available_gateways;
}
代码进入您的活动子主题(或活动主题)的 functions.php 文件。已测试并有效。
For Woocommerce default Paypal payment gateway, replace
'ppec_paypal'
by'paypal'
.