Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active August 9, 2016 07:20
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 xadapter/787a167d35e3e0ff314d83d1b065da1f to your computer and use it in GitHub Desktop.
Save xadapter/787a167d35e3e0ff314d83d1b065da1f to your computer and use it in GitHub Desktop.
Change WooCommerce Cart / Checkout Options based on User Role and Country
add_action('woocommerce_available_payment_gateways', 'xa_change_optins_based_on_user_role');
function xa_change_optins_based_on_user_role(){
global $woocommerce;
// Check with the capability which is unique to the particular user role.
if( current_user_can( 'edit_posts' ) {
//
if ( isset( $available_gateways['ccavenue'] ) && $woocommerce->customer->get_country() <> 'IN' ) {
unset( $available_gateways['ccavenue'] );
} else if ( isset( $available_gateways['paypal'] ) && $woocommerce->customer->get_country() == 'IN' ) {
unset( $available_gateways['paypal'] );
}
return $available_gateways;
}
return $available_gateways;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment