S
S
Sergei Gurdjiyan2018-02-18 12:05:00
WordPress
Sergei Gurdjiyan, 2018-02-18 12:05:00

How to restrict payment method in Woocommerce to only a specific user role?

Actually, you need to make a restriction in the choice of payment in the Woocommerce cart.
So that it would be possible in the settings of the payment method or elsewhere to select for which user role this method is available. Are there any plugins for this task?
If not, how can it be implemented in code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mike, 2018-02-18
@MikeKosulin

Plugin
Manually in Code Snippets or functions.php

add_filter('woocommerce_available_payment_gateways', 'yourslug_filter_gateways', 10);
  function yourslug_filter_gateways($gateways)
  {
      $current_user = wp_get_current_user();
      $role = $current_user->roles;
      global $woocommerce;
      /* добавить роль в условие или метод оплаты, который нужно исключить*/
      if ($role[0] == 'administrator') {
          unset($gateways['cod']);
      }
      return $gateways;
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question