最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Enable Payment gateway if ACF checkbox in user profile is checked

programmeradmin12浏览0评论

I have added a way to enable the Woocommerce COD (cash on delivery) payment gateway for a user role of "account holder".

/**
* 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' );

Instead I would like to enable this payment gateway if an ACF (advanced custom fields pro) checkbox in their user profile is checked.

How can I do this?

I have added a way to enable the Woocommerce COD (cash on delivery) payment gateway for a user role of "account holder".

/**
* 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' );

Instead I would like to enable this payment gateway if an ACF (advanced custom fields pro) checkbox in their user profile is checked.

How can I do this?

Share Improve this question asked Jun 19, 2019 at 19:24 Chris CChris C 12 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

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' );
发布评论

评论列表(0)

  1. 暂无评论