wc_customer_has_capability

Checks if a user has a certain capability.

Description

wc_customer_has_capability( (array) $allcaps, (array) $caps, (array) $args ); 

Parameters (3)

0. $allcaps (array)
The allcaps.
1. $caps (array)
The caps.
2. $args (array)
The args.

Usage

  1. if ( !function_exists( 'wc_customer_has_capability' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-user-functions.php'; 
  3.  
  4. // The allcaps. 
  5. $allcaps = array(); 
  6.  
  7. // The caps. 
  8. $caps = array(); 
  9.  
  10. // The args. 
  11. $args = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wc_customer_has_capability($allcaps, $caps, $args); 
  15.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-user-functions.php  
  1. function wc_customer_has_capability( $allcaps, $caps, $args ) { 
  2. if ( isset( $caps[0] ) ) { 
  3. switch ( $caps[0] ) { 
  4. case 'view_order' : 
  5. $user_id = $args[1]; 
  6. $order = wc_get_order( $args[2] ); 
  7.  
  8. if ( $order && $user_id == $order->get_user_id() ) { 
  9. $allcaps['view_order'] = true; 
  10. break; 
  11. case 'pay_for_order' : 
  12. $user_id = $args[1]; 
  13. $order_id = isset( $args[2] ) ? $args[2] : null; 
  14.  
  15. // When no order ID, we assume it's a new order 
  16. // and thus, customer can pay for it 
  17. if ( ! $order_id ) { 
  18. $allcaps['pay_for_order'] = true; 
  19. break; 
  20.  
  21. $order = wc_get_order( $order_id ); 
  22.  
  23. if ( $order && ( $user_id == $order->get_user_id() || ! $order->get_user_id() ) ) { 
  24. $allcaps['pay_for_order'] = true; 
  25. break; 
  26. case 'order_again' : 
  27. $user_id = $args[1]; 
  28. $order = wc_get_order( $args[2] ); 
  29.  
  30. if ( $order && $user_id == $order->get_user_id() ) { 
  31. $allcaps['order_again'] = true; 
  32. break; 
  33. case 'cancel_order' : 
  34. $user_id = $args[1]; 
  35. $order = wc_get_order( $args[2] ); 
  36.  
  37. if ( $order && $user_id == $order->get_user_id() ) { 
  38. $allcaps['cancel_order'] = true; 
  39. break; 
  40. case 'download_file' : 
  41. $user_id = $args[1]; 
  42. $download = $args[2]; 
  43.  
  44. if ( $download && $user_id == $download->get_user_id() ) { 
  45. $allcaps['download_file'] = true; 
  46. break; 
  47. return $allcaps;