尝试有条件地隐藏 WooCommerce 中的 Square
Trying to Conditionally Hide Square in WooCommerce
我有一个客户只想向商店经理和管理员展示 WooCommerce 中的 Square 付款方式。他们还想隐藏其他付款方式。例如,bacs、cod 和支票。以下代码适用于 Square 以外的任何内容:
add_filter( 'woocommerce_available_payment_gateways', 'client_pmts_enable_manager' );
function client_pmts_enable_manager( $available_gateways ) {
if ( isset( $available_gateways['bacs'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['bacs'] );
}
if ( isset( $available_gateways['cod'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['cod'] );
}
if ( isset( $available_gateways['cheque'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['cheque'] );
}
if ( isset( $available_gateways['square'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['square'] );
}
return $available_gateways;
}
任何人都可以帮我找到 Square 网关的名称,以便我可以为 non-admin/shop 位管理员取消设置吗?
尝试以下,我认为 ID 实际上是“square_credit_card”:
add_filter( 'woocommerce_available_payment_gateways', 'client_pmts_enable_manager' );
function client_pmts_enable_manager( $available_gateways ) {
if ( isset( $available_gateways['bacs'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['bacs'] );
}
if ( isset( $available_gateways['cod'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['cod'] );
}
if ( isset( $available_gateways['cheque'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['cheque'] );
}
if ( isset( $available_gateways['square_credit_card'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['square_credit_card'] );
}
return $available_gateways;
}
我有一个客户只想向商店经理和管理员展示 WooCommerce 中的 Square 付款方式。他们还想隐藏其他付款方式。例如,bacs、cod 和支票。以下代码适用于 Square 以外的任何内容:
add_filter( 'woocommerce_available_payment_gateways', 'client_pmts_enable_manager' );
function client_pmts_enable_manager( $available_gateways ) {
if ( isset( $available_gateways['bacs'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['bacs'] );
}
if ( isset( $available_gateways['cod'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['cod'] );
}
if ( isset( $available_gateways['cheque'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['cheque'] );
}
if ( isset( $available_gateways['square'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['square'] );
}
return $available_gateways;
}
任何人都可以帮我找到 Square 网关的名称,以便我可以为 non-admin/shop 位管理员取消设置吗?
尝试以下,我认为 ID 实际上是“square_credit_card”:
add_filter( 'woocommerce_available_payment_gateways', 'client_pmts_enable_manager' );
function client_pmts_enable_manager( $available_gateways ) {
if ( isset( $available_gateways['bacs'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['bacs'] );
}
if ( isset( $available_gateways['cod'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['cod'] );
}
if ( isset( $available_gateways['cheque'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['cheque'] );
}
if ( isset( $available_gateways['square_credit_card'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
unset( $available_gateways['square_credit_card'] );
}
return $available_gateways;
}