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 01 Answer
Reset to default 0Found 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' );