class-wc-rest-controller.php
1 year ago
class-wc-rest-coupons-controller.php
4 years ago
class-wc-rest-crud-controller.php
7 months ago
class-wc-rest-customer-downloads-controller.php
5 years ago
class-wc-rest-customers-controller.php
3 years ago
class-wc-rest-data-continents-controller.php
4 months ago
class-wc-rest-data-controller.php
5 years ago
class-wc-rest-data-countries-controller.php
4 months ago
class-wc-rest-data-currencies-controller.php
4 months ago
class-wc-rest-layout-templates-controller.php
2 years ago
class-wc-rest-network-orders-controller.php
5 years ago
class-wc-rest-order-notes-controller.php
5 years ago
class-wc-rest-order-refunds-controller.php
2 months ago
class-wc-rest-orders-controller.php
2 months ago
class-wc-rest-payment-gateways-controller.php
1 year ago
class-wc-rest-paypal-buttons-controller.php
5 months ago
class-wc-rest-paypal-standard-controller.php
3 months ago
class-wc-rest-paypal-webhooks-controller.php
3 months ago
class-wc-rest-posts-controller.php
2 years ago
class-wc-rest-product-attribute-terms-controller.php
5 years ago
class-wc-rest-product-attributes-controller.php
2 years ago
class-wc-rest-product-brands-controller.php
1 year ago
class-wc-rest-product-categories-controller.php
3 months ago
class-wc-rest-product-custom-fields-controller.php
1 year ago
class-wc-rest-product-reviews-controller.php
1 year ago
class-wc-rest-product-shipping-classes-controller.php
1 year ago
class-wc-rest-product-tags-controller.php
5 years ago
class-wc-rest-product-variations-controller.php
1 month ago
class-wc-rest-products-catalog-controller.php
7 months ago
class-wc-rest-products-controller.php
2 months ago
class-wc-rest-refunds-controller.php
2 years ago
class-wc-rest-report-coupons-totals-controller.php
5 years ago
class-wc-rest-report-customers-totals-controller.php
5 years ago
class-wc-rest-report-orders-totals-controller.php
2 years ago
class-wc-rest-report-products-totals-controller.php
5 years ago
class-wc-rest-report-reviews-totals-controller.php
5 years ago
class-wc-rest-report-sales-controller.php
5 years ago
class-wc-rest-report-top-sellers-controller.php
5 years ago
class-wc-rest-reports-controller.php
5 years ago
class-wc-rest-setting-options-controller.php
4 months ago
class-wc-rest-settings-controller.php
5 years ago
class-wc-rest-shipping-methods-controller.php
5 years ago
class-wc-rest-shipping-zone-locations-controller.php
5 years ago
class-wc-rest-shipping-zone-methods-controller.php
5 years ago
class-wc-rest-shipping-zones-controller-base.php
5 years ago
class-wc-rest-shipping-zones-controller.php
5 years ago
class-wc-rest-system-status-controller.php
5 years ago
class-wc-rest-system-status-tools-controller.php
5 years ago
class-wc-rest-tax-classes-controller.php
5 years ago
class-wc-rest-taxes-controller.php
5 years ago
class-wc-rest-terms-controller.php
1 month ago
class-wc-rest-variations-controller.php
9 months ago
class-wc-rest-webhooks-controller.php
5 years ago
class-wc-rest-customers-controller.php
286 lines
| 1 | <?php |
| 2 | /** |
| 3 | * REST API Customers controller |
| 4 | * |
| 5 | * Handles requests to the /customers endpoint. |
| 6 | * |
| 7 | * @package WooCommerce\RestApi |
| 8 | * @since 2.6.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | /** |
| 14 | * REST API Customers controller class. |
| 15 | * |
| 16 | * @package WooCommerce\RestApi |
| 17 | * @extends WC_REST_Customers_V2_Controller |
| 18 | */ |
| 19 | class WC_REST_Customers_Controller extends WC_REST_Customers_V2_Controller { |
| 20 | |
| 21 | /** |
| 22 | * Endpoint namespace. |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | protected $namespace = 'wc/v3'; |
| 27 | |
| 28 | /** |
| 29 | * Get formatted item data. |
| 30 | * |
| 31 | * @param WC_Data $object WC_Data instance. |
| 32 | * |
| 33 | * @since 3.0.0 |
| 34 | * @return array |
| 35 | */ |
| 36 | protected function get_formatted_item_data( $object ) { |
| 37 | return $this->get_formatted_item_data_core( $object ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Get the Customer's schema, conforming to JSON Schema. |
| 42 | * |
| 43 | * @return array |
| 44 | */ |
| 45 | public function get_item_schema() { |
| 46 | $schema = array( |
| 47 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 48 | 'title' => 'customer', |
| 49 | 'type' => 'object', |
| 50 | 'properties' => array( |
| 51 | 'id' => array( |
| 52 | 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
| 53 | 'type' => 'integer', |
| 54 | 'context' => array( 'view', 'edit' ), |
| 55 | 'readonly' => true, |
| 56 | ), |
| 57 | 'date_created' => array( |
| 58 | 'description' => __( "The date the customer was created, in the site's timezone.", 'woocommerce' ), |
| 59 | 'type' => 'date-time', |
| 60 | 'context' => array( 'view', 'edit' ), |
| 61 | 'readonly' => true, |
| 62 | ), |
| 63 | 'date_created_gmt' => array( |
| 64 | 'description' => __( 'The date the customer was created, as GMT.', 'woocommerce' ), |
| 65 | 'type' => 'date-time', |
| 66 | 'context' => array( 'view', 'edit' ), |
| 67 | 'readonly' => true, |
| 68 | ), |
| 69 | 'date_modified' => array( |
| 70 | 'description' => __( "The date the customer was last modified, in the site's timezone.", 'woocommerce' ), |
| 71 | 'type' => 'date-time', |
| 72 | 'context' => array( 'view', 'edit' ), |
| 73 | 'readonly' => true, |
| 74 | ), |
| 75 | 'date_modified_gmt' => array( |
| 76 | 'description' => __( 'The date the customer was last modified, as GMT.', 'woocommerce' ), |
| 77 | 'type' => 'date-time', |
| 78 | 'context' => array( 'view', 'edit' ), |
| 79 | 'readonly' => true, |
| 80 | ), |
| 81 | 'email' => array( |
| 82 | 'description' => __( 'The email address for the customer.', 'woocommerce' ), |
| 83 | 'type' => 'string', |
| 84 | 'format' => 'email', |
| 85 | 'context' => array( 'view', 'edit' ), |
| 86 | ), |
| 87 | 'first_name' => array( |
| 88 | 'description' => __( 'Customer first name.', 'woocommerce' ), |
| 89 | 'type' => 'string', |
| 90 | 'context' => array( 'view', 'edit' ), |
| 91 | 'arg_options' => array( |
| 92 | 'sanitize_callback' => 'sanitize_text_field', |
| 93 | ), |
| 94 | ), |
| 95 | 'last_name' => array( |
| 96 | 'description' => __( 'Customer last name.', 'woocommerce' ), |
| 97 | 'type' => 'string', |
| 98 | 'context' => array( 'view', 'edit' ), |
| 99 | 'arg_options' => array( |
| 100 | 'sanitize_callback' => 'sanitize_text_field', |
| 101 | ), |
| 102 | ), |
| 103 | 'role' => array( |
| 104 | 'description' => __( 'Customer role.', 'woocommerce' ), |
| 105 | 'type' => 'string', |
| 106 | 'context' => array( 'view', 'edit' ), |
| 107 | 'readonly' => true, |
| 108 | ), |
| 109 | 'username' => array( |
| 110 | 'description' => __( 'Customer login name.', 'woocommerce' ), |
| 111 | 'type' => 'string', |
| 112 | 'context' => array( 'view', 'edit' ), |
| 113 | 'arg_options' => array( |
| 114 | 'sanitize_callback' => 'sanitize_user', |
| 115 | ), |
| 116 | ), |
| 117 | 'password' => array( |
| 118 | 'description' => __( 'Customer password.', 'woocommerce' ), |
| 119 | 'type' => 'string', |
| 120 | 'context' => array( 'edit' ), |
| 121 | ), |
| 122 | 'billing' => array( |
| 123 | 'description' => __( 'List of billing address data.', 'woocommerce' ), |
| 124 | 'type' => 'object', |
| 125 | 'context' => array( 'view', 'edit' ), |
| 126 | 'properties' => array( |
| 127 | 'first_name' => array( |
| 128 | 'description' => __( 'First name.', 'woocommerce' ), |
| 129 | 'type' => 'string', |
| 130 | 'context' => array( 'view', 'edit' ), |
| 131 | ), |
| 132 | 'last_name' => array( |
| 133 | 'description' => __( 'Last name.', 'woocommerce' ), |
| 134 | 'type' => 'string', |
| 135 | 'context' => array( 'view', 'edit' ), |
| 136 | ), |
| 137 | 'company' => array( |
| 138 | 'description' => __( 'Company name.', 'woocommerce' ), |
| 139 | 'type' => 'string', |
| 140 | 'context' => array( 'view', 'edit' ), |
| 141 | ), |
| 142 | 'address_1' => array( |
| 143 | 'description' => __( 'Address line 1', 'woocommerce' ), |
| 144 | 'type' => 'string', |
| 145 | 'context' => array( 'view', 'edit' ), |
| 146 | ), |
| 147 | 'address_2' => array( |
| 148 | 'description' => __( 'Address line 2', 'woocommerce' ), |
| 149 | 'type' => 'string', |
| 150 | 'context' => array( 'view', 'edit' ), |
| 151 | ), |
| 152 | 'city' => array( |
| 153 | 'description' => __( 'City name.', 'woocommerce' ), |
| 154 | 'type' => 'string', |
| 155 | 'context' => array( 'view', 'edit' ), |
| 156 | ), |
| 157 | 'state' => array( |
| 158 | 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
| 159 | 'type' => 'string', |
| 160 | 'context' => array( 'view', 'edit' ), |
| 161 | ), |
| 162 | 'postcode' => array( |
| 163 | 'description' => __( 'Postal code.', 'woocommerce' ), |
| 164 | 'type' => 'string', |
| 165 | 'context' => array( 'view', 'edit' ), |
| 166 | ), |
| 167 | 'country' => array( |
| 168 | 'description' => __( 'ISO code of the country.', 'woocommerce' ), |
| 169 | 'type' => 'string', |
| 170 | 'context' => array( 'view', 'edit' ), |
| 171 | ), |
| 172 | 'email' => array( |
| 173 | 'description' => __( 'Email address.', 'woocommerce' ), |
| 174 | 'type' => 'string', |
| 175 | 'format' => 'email', |
| 176 | 'context' => array( 'view', 'edit' ), |
| 177 | ), |
| 178 | 'phone' => array( |
| 179 | 'description' => __( 'Phone number.', 'woocommerce' ), |
| 180 | 'type' => 'string', |
| 181 | 'context' => array( 'view', 'edit' ), |
| 182 | ), |
| 183 | ), |
| 184 | ), |
| 185 | 'shipping' => array( |
| 186 | 'description' => __( 'List of shipping address data.', 'woocommerce' ), |
| 187 | 'type' => 'object', |
| 188 | 'context' => array( 'view', 'edit' ), |
| 189 | 'properties' => array( |
| 190 | 'first_name' => array( |
| 191 | 'description' => __( 'First name.', 'woocommerce' ), |
| 192 | 'type' => 'string', |
| 193 | 'context' => array( 'view', 'edit' ), |
| 194 | ), |
| 195 | 'last_name' => array( |
| 196 | 'description' => __( 'Last name.', 'woocommerce' ), |
| 197 | 'type' => 'string', |
| 198 | 'context' => array( 'view', 'edit' ), |
| 199 | ), |
| 200 | 'company' => array( |
| 201 | 'description' => __( 'Company name.', 'woocommerce' ), |
| 202 | 'type' => 'string', |
| 203 | 'context' => array( 'view', 'edit' ), |
| 204 | ), |
| 205 | 'address_1' => array( |
| 206 | 'description' => __( 'Address line 1', 'woocommerce' ), |
| 207 | 'type' => 'string', |
| 208 | 'context' => array( 'view', 'edit' ), |
| 209 | ), |
| 210 | 'address_2' => array( |
| 211 | 'description' => __( 'Address line 2', 'woocommerce' ), |
| 212 | 'type' => 'string', |
| 213 | 'context' => array( 'view', 'edit' ), |
| 214 | ), |
| 215 | 'city' => array( |
| 216 | 'description' => __( 'City name.', 'woocommerce' ), |
| 217 | 'type' => 'string', |
| 218 | 'context' => array( 'view', 'edit' ), |
| 219 | ), |
| 220 | 'state' => array( |
| 221 | 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
| 222 | 'type' => 'string', |
| 223 | 'context' => array( 'view', 'edit' ), |
| 224 | ), |
| 225 | 'postcode' => array( |
| 226 | 'description' => __( 'Postal code.', 'woocommerce' ), |
| 227 | 'type' => 'string', |
| 228 | 'context' => array( 'view', 'edit' ), |
| 229 | ), |
| 230 | 'country' => array( |
| 231 | 'description' => __( 'ISO code of the country.', 'woocommerce' ), |
| 232 | 'type' => 'string', |
| 233 | 'context' => array( 'view', 'edit' ), |
| 234 | ), |
| 235 | 'phone' => array( |
| 236 | 'description' => __( 'Phone number.', 'woocommerce' ), |
| 237 | 'type' => 'string', |
| 238 | 'context' => array( 'view', 'edit' ), |
| 239 | ), |
| 240 | ), |
| 241 | ), |
| 242 | 'is_paying_customer' => array( |
| 243 | 'description' => __( 'Is the customer a paying customer?', 'woocommerce' ), |
| 244 | 'type' => 'bool', |
| 245 | 'context' => array( 'view', 'edit' ), |
| 246 | 'readonly' => true, |
| 247 | ), |
| 248 | 'avatar_url' => array( |
| 249 | 'description' => __( 'Avatar URL.', 'woocommerce' ), |
| 250 | 'type' => 'string', |
| 251 | 'context' => array( 'view', 'edit' ), |
| 252 | 'readonly' => true, |
| 253 | ), |
| 254 | 'meta_data' => array( |
| 255 | 'description' => __( 'Meta data.', 'woocommerce' ), |
| 256 | 'type' => 'array', |
| 257 | 'context' => array( 'view', 'edit' ), |
| 258 | 'items' => array( |
| 259 | 'type' => 'object', |
| 260 | 'properties' => array( |
| 261 | 'id' => array( |
| 262 | 'description' => __( 'Meta ID.', 'woocommerce' ), |
| 263 | 'type' => 'integer', |
| 264 | 'context' => array( 'view', 'edit' ), |
| 265 | 'readonly' => true, |
| 266 | ), |
| 267 | 'key' => array( |
| 268 | 'description' => __( 'Meta key.', 'woocommerce' ), |
| 269 | 'type' => 'string', |
| 270 | 'context' => array( 'view', 'edit' ), |
| 271 | ), |
| 272 | 'value' => array( |
| 273 | 'description' => __( 'Meta value.', 'woocommerce' ), |
| 274 | 'type' => 'mixed', |
| 275 | 'context' => array( 'view', 'edit' ), |
| 276 | ), |
| 277 | ), |
| 278 | ), |
| 279 | ), |
| 280 | ), |
| 281 | ); |
| 282 | |
| 283 | return $this->add_additional_fields_schema( $schema ); |
| 284 | } |
| 285 | } |
| 286 |