WC_REST_Shipping_Zones_Controller_Base

REST API Shipping Zones base class.

Defined (1)

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

/includes/abstracts/abstract-wc-rest-shipping-zones-controller.php  
  1. abstract class WC_REST_Shipping_Zones_Controller_Base extends WC_REST_Controller { 
  2.  
  3. /** 
  4. * Endpoint namespace. 
  5. * @var string 
  6. */ 
  7. protected $namespace = 'wc/v2'; 
  8.  
  9. /** 
  10. * Route base. 
  11. * @var string 
  12. */ 
  13. protected $rest_base = 'shipping/zones'; 
  14.  
  15. /** 
  16. * Retrieve a Shipping Zone by it's ID. 
  17. * @param int $zone_id Shipping Zone ID. 
  18. * @return WC_Shipping_Zone|WP_Error 
  19. */ 
  20. protected function get_zone( $zone_id ) { 
  21. $zone = WC_Shipping_Zones::get_zone_by( 'zone_id', $zone_id ); 
  22.  
  23. if ( false === $zone ) { 
  24. return new WP_Error( 'woocommerce_rest_shipping_zone_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); 
  25.  
  26. return $zone; 
  27.  
  28. /** 
  29. * Check whether a given request has permission to read Shipping Zones. 
  30. * @param WP_REST_Request $request Full details about the request. 
  31. * @return WP_Error|boolean 
  32. */ 
  33. public function get_items_permissions_check( $request ) { 
  34. if ( ! wc_shipping_enabled() ) { 
  35. return new WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); 
  36.  
  37. if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { 
  38. return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); 
  39.  
  40. return true; 
  41.  
  42. /** 
  43. * Check if a given request has access to create Shipping Zones. 
  44. * @param WP_REST_Request $request Full details about the request. 
  45. * @return WP_Error|boolean 
  46. */ 
  47. public function create_item_permissions_check( $request ) { 
  48. if ( ! wc_shipping_enabled() ) { 
  49. return new WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); 
  50.  
  51. if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { 
  52. return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); 
  53.  
  54. return true; 
  55.  
  56. /** 
  57. * Check whether a given request has permission to edit Shipping Zones. 
  58. * @param WP_REST_Request $request Full details about the request. 
  59. * @return WP_Error|boolean 
  60. */ 
  61. public function update_items_permissions_check( $request ) { 
  62. if ( ! wc_shipping_enabled() ) { 
  63. return new WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); 
  64.  
  65. if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { 
  66. return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); 
  67.  
  68. return true; 
  69.  
  70. /** 
  71. * Check whether a given request has permission to delete Shipping Zones. 
  72. * @param WP_REST_Request $request Full details about the request. 
  73. * @return WP_Error|boolean 
  74. */ 
  75. public function delete_items_permissions_check( $request ) { 
  76. if ( ! wc_shipping_enabled() ) { 
  77. return new WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); 
  78.  
  79. if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { 
  80. return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); 
  81.  
  82. return true; 
  83.