如果选中用户配置文件中的ACF复选框则启用支付网关

时间:2019-06-19 作者:Chris C

我添加了一种方法,可以为“账户持有人”用户角色启用Woocommerce COD(货到付款)支付网关。

/**
* Enable COD
*/
function cod_enable_manager( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways[\'cod\'] ) && 
!current_user_can(\'account_holder\') ) {
unset( $available_gateways[\'cod\'] );
} 
return $available_gateways;
}

add_filter( \'woocommerce_available_payment_gateways\', \'cod_enable_manager\' );
相反,如果选中用户配置文件中的ACF(advanced custom fields pro)复选框,我想启用此支付网关。

我该怎么做?

1 个回复
SO网友:Chris C

Found my solution

/*
 * Enable COD for account holder
 */
function enable_cod_payment( $available_gateways ) {

  global $woocommerce;
  $user = wp_get_current_user();
  $user_status = get_field(\'account_holder\', $user );

  if ($user_status == \'Yes\')  {
    $available_gateways[\'cod\'];
    unset( $available_gateways[\'authorize_net_cim_credit_card\'] );
  }
  else {
    unset( $available_gateways[\'cod\'] );
  }

  return $available_gateways;
}
add_filter( \'woocommerce_available_payment_gateways\', \'enable_cod_payment\' );

相关推荐