title: Pay without need to login WooCommerce
body: <p>For a WooCommerce webshop we send out a lot of payment links through email. Before getting to the payment page customers are obligated to login first. We would like the customer to be able to complete payment without logging in as often they don't know their password because of different company departments.</p>
  
  <p>I found this code but this only lets the administrator pay without logging in:</p>
  
  <pre><code>function your_custom_function_name($allcaps, $caps, $args)
  {
      if (isset($caps[0])) {
          switch ($caps[0]) {
          case 'pay_for_order':
              $user_id = $args[1];
              $order_id = isset($args[2]) ? $args[2] : null;
  
              // When no order ID, we assume it's a new order
              // and thus, customer can pay for it
  
              if (!$order_id) {
                  $allcaps['pay_for_order'] = true;
                  break;
              }
  
              $user = get_userdata($user_id);
              if (in_array('administrator', (array)$user-&gt;roles)) {
                  $allcaps['pay_for_order'] = true;
              }
  
              $order = wc_get_order($order_id);
              if ($order &amp;&amp; ($user_id == $order-&gt;get_user_id() || !$order - &gt; get_user_id())) {
                  $allcaps['pay_for_order'] = true;
              }
  
              break;
          }
      }
  
      return $allcaps;
  }
  
  add_filter('user_has_cap', 'your_custom_function_name', 10, 3);
  </code></pre>