samedi 15 août 2020

Allow customer to pay by cheque if their account is approved in WooCommerce

By default the store only accepts credit card but I need to allow some pre-approved customers to have the ability to pay by check.

I got this working with a custom user role and the following code:

add_filter( 'woocommerce_available_payment_gateways', 'allow_to_pay_by_check' );

function allow_to_pay_by_check( $available_gateways ) {
   if ( isset( $available_gateways['cheque'] ) && ! current_user_can('pay_using_cheque') ) {
      unset( $available_gateways['cheque'] );
   } 
   return $available_gateways;
}

It works and gives them the ability to pay by check AND credit cards. The issue is that I don't think this should be a user role. It should be located under each customer (Users) account details as a check box to turn on or off. Is this possible?




Aucun commentaire:

Enregistrer un commentaire