Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cccamuseme/2627d5889b7d75c82d367cc5ea015ea0 to your computer and use it in GitHub Desktop.
Save cccamuseme/2627d5889b7d75c82d367cc5ea015ea0 to your computer and use it in GitHub Desktop.
Enable or disable woocommerce payment gateway by ACF radio buttons in user profile.
<?php
/*
* 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' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment