Completed
Push — master ( a986bf...ee9494 )
by Mike
104:12 queued 59:10
created
src/Controllers/Version2/class-wc-rest-settings-v2-controller.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   3.0.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Settings controller class.
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 			$this->namespace, '/' . $this->rest_base, array(
43 43
 				array(
44 44
 					'methods'             => WP_REST_Server::READABLE,
45
-					'callback'            => array( $this, 'get_items' ),
46
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
45
+					'callback'            => array($this, 'get_items'),
46
+					'permission_callback' => array($this, 'get_items_permissions_check'),
47 47
 				),
48
-				'schema' => array( $this, 'get_public_item_schema' ),
48
+				'schema' => array($this, 'get_public_item_schema'),
49 49
 			)
50 50
 		);
51 51
 	}
@@ -57,34 +57,34 @@  discard block
 block discarded – undo
57 57
 	 * @param  WP_REST_Request $request Request data.
58 58
 	 * @return WP_Error|WP_REST_Response
59 59
 	 */
60
-	public function get_items( $request ) {
61
-		$groups = apply_filters( 'woocommerce_settings_groups', array() );
62
-		if ( empty( $groups ) ) {
63
-			return new WP_Error( 'rest_setting_groups_empty', __( 'No setting groups have been registered.', 'woocommerce' ), array( 'status' => 500 ) );
60
+	public function get_items($request) {
61
+		$groups = apply_filters('woocommerce_settings_groups', array());
62
+		if (empty($groups)) {
63
+			return new WP_Error('rest_setting_groups_empty', __('No setting groups have been registered.', 'woocommerce'), array('status' => 500));
64 64
 		}
65 65
 
66 66
 		$defaults        = $this->group_defaults();
67 67
 		$filtered_groups = array();
68
-		foreach ( $groups as $group ) {
68
+		foreach ($groups as $group) {
69 69
 			$sub_groups = array();
70
-			foreach ( $groups as $_group ) {
71
-				if ( ! empty( $_group['parent_id'] ) && $group['id'] === $_group['parent_id'] ) {
70
+			foreach ($groups as $_group) {
71
+				if ( ! empty($_group['parent_id']) && $group['id'] === $_group['parent_id']) {
72 72
 					$sub_groups[] = $_group['id'];
73 73
 				}
74 74
 			}
75 75
 			$group['sub_groups'] = $sub_groups;
76 76
 
77
-			$group = wp_parse_args( $group, $defaults );
78
-			if ( ! is_null( $group['id'] ) && ! is_null( $group['label'] ) ) {
79
-				$group_obj  = $this->filter_group( $group );
80
-				$group_data = $this->prepare_item_for_response( $group_obj, $request );
81
-				$group_data = $this->prepare_response_for_collection( $group_data );
77
+			$group = wp_parse_args($group, $defaults);
78
+			if ( ! is_null($group['id']) && ! is_null($group['label'])) {
79
+				$group_obj  = $this->filter_group($group);
80
+				$group_data = $this->prepare_item_for_response($group_obj, $request);
81
+				$group_data = $this->prepare_response_for_collection($group_data);
82 82
 
83 83
 				$filtered_groups[] = $group_data;
84 84
 			}
85 85
 		}
86 86
 
87
-		$response = rest_ensure_response( $filtered_groups );
87
+		$response = rest_ensure_response($filtered_groups);
88 88
 		return $response;
89 89
 	}
90 90
 
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
 	 * @param string $group_id Group ID.
95 95
 	 * @return array Links for the given group.
96 96
 	 */
97
-	protected function prepare_links( $group_id ) {
97
+	protected function prepare_links($group_id) {
98 98
 		$base  = '/' . $this->namespace . '/' . $this->rest_base;
99 99
 		$links = array(
100 100
 			'options' => array(
101
-				'href' => rest_url( trailingslashit( $base ) . $group_id ),
101
+				'href' => rest_url(trailingslashit($base) . $group_id),
102 102
 			),
103 103
 		);
104 104
 
@@ -113,14 +113,14 @@  discard block
 block discarded – undo
113 113
 	 * @param WP_REST_Request $request Request object.
114 114
 	 * @return WP_REST_Response $response Response data.
115 115
 	 */
116
-	public function prepare_item_for_response( $item, $request ) {
117
-		$context = empty( $request['context'] ) ? 'view' : $request['context'];
118
-		$data    = $this->add_additional_fields_to_object( $item, $request );
119
-		$data    = $this->filter_response_by_context( $data, $context );
116
+	public function prepare_item_for_response($item, $request) {
117
+		$context = empty($request['context']) ? 'view' : $request['context'];
118
+		$data    = $this->add_additional_fields_to_object($item, $request);
119
+		$data    = $this->filter_response_by_context($data, $context);
120 120
 
121
-		$response = rest_ensure_response( $data );
121
+		$response = rest_ensure_response($data);
122 122
 
123
-		$response->add_links( $this->prepare_links( $item['id'] ) );
123
+		$response->add_links($this->prepare_links($item['id']));
124 124
 
125 125
 		return $response;
126 126
 	}
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 	 * @param  array $group Group.
134 134
 	 * @return array
135 135
 	 */
136
-	public function filter_group( $group ) {
136
+	public function filter_group($group) {
137 137
 		return array_intersect_key(
138 138
 			$group,
139
-			array_flip( array_filter( array_keys( $group ), array( $this, 'allowed_group_keys' ) ) )
139
+			array_flip(array_filter(array_keys($group), array($this, 'allowed_group_keys')))
140 140
 		);
141 141
 	}
142 142
 
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
 	 * @param  string $key Key to check.
148 148
 	 * @return boolean
149 149
 	 */
150
-	public function allowed_group_keys( $key ) {
151
-		return in_array( $key, array( 'id', 'label', 'description', 'parent_id', 'sub_groups' ) );
150
+	public function allowed_group_keys($key) {
151
+		return in_array($key, array('id', 'label', 'description', 'parent_id', 'sub_groups'));
152 152
 	}
153 153
 
154 154
 	/**
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
 	 * @param WP_REST_Request $request Full data about the request.
175 175
 	 * @return WP_Error|boolean
176 176
 	 */
177
-	public function get_items_permissions_check( $request ) {
178
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
179
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
177
+	public function get_items_permissions_check($request) {
178
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
179
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
180 180
 		}
181 181
 
182 182
 		return true;
@@ -195,38 +195,38 @@  discard block
 block discarded – undo
195 195
 			'type'       => 'object',
196 196
 			'properties' => array(
197 197
 				'id'          => array(
198
-					'description' => __( 'A unique identifier that can be used to link settings together.', 'woocommerce' ),
198
+					'description' => __('A unique identifier that can be used to link settings together.', 'woocommerce'),
199 199
 					'type'        => 'string',
200
-					'context'     => array( 'view' ),
200
+					'context'     => array('view'),
201 201
 					'readonly'    => true,
202 202
 				),
203 203
 				'label'       => array(
204
-					'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
204
+					'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'),
205 205
 					'type'        => 'string',
206
-					'context'     => array( 'view' ),
206
+					'context'     => array('view'),
207 207
 					'readonly'    => true,
208 208
 				),
209 209
 				'description' => array(
210
-					'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
210
+					'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'),
211 211
 					'type'        => 'string',
212
-					'context'     => array( 'view' ),
212
+					'context'     => array('view'),
213 213
 					'readonly'    => true,
214 214
 				),
215 215
 				'parent_id'   => array(
216
-					'description' => __( 'ID of parent grouping.', 'woocommerce' ),
216
+					'description' => __('ID of parent grouping.', 'woocommerce'),
217 217
 					'type'        => 'string',
218
-					'context'     => array( 'view' ),
218
+					'context'     => array('view'),
219 219
 					'readonly'    => true,
220 220
 				),
221 221
 				'sub_groups'  => array(
222
-					'description' => __( 'IDs for settings sub groups.', 'woocommerce' ),
222
+					'description' => __('IDs for settings sub groups.', 'woocommerce'),
223 223
 					'type'        => 'string',
224
-					'context'     => array( 'view' ),
224
+					'context'     => array('view'),
225 225
 					'readonly'    => true,
226 226
 				),
227 227
 			),
228 228
 		);
229 229
 
230
-		return $this->add_additional_fields_schema( $schema );
230
+		return $this->add_additional_fields_schema($schema);
231 231
 	}
232 232
 }
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-report-sales-v2-controller.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Report Sales controller class.
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-products-v2-controller.php 1 patch
Spacing   +680 added lines, -680 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Products controller class.
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * Initialize product actions.
51 51
 	 */
52 52
 	public function __construct() {
53
-		add_action( "woocommerce_rest_insert_{$this->post_type}_object", array( $this, 'clear_transients' ) );
53
+		add_action("woocommerce_rest_insert_{$this->post_type}_object", array($this, 'clear_transients'));
54 54
 	}
55 55
 
56 56
 	/**
@@ -63,17 +63,17 @@  discard block
 block discarded – undo
63 63
 			array(
64 64
 				array(
65 65
 					'methods'             => WP_REST_Server::READABLE,
66
-					'callback'            => array( $this, 'get_items' ),
67
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
66
+					'callback'            => array($this, 'get_items'),
67
+					'permission_callback' => array($this, 'get_items_permissions_check'),
68 68
 					'args'                => $this->get_collection_params(),
69 69
 				),
70 70
 				array(
71 71
 					'methods'             => WP_REST_Server::CREATABLE,
72
-					'callback'            => array( $this, 'create_item' ),
73
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
74
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
72
+					'callback'            => array($this, 'create_item'),
73
+					'permission_callback' => array($this, 'create_item_permissions_check'),
74
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
75 75
 				),
76
-				'schema' => array( $this, 'get_public_item_schema' ),
76
+				'schema' => array($this, 'get_public_item_schema'),
77 77
 			)
78 78
 		);
79 79
 
@@ -83,14 +83,14 @@  discard block
 block discarded – undo
83 83
 			array(
84 84
 				'args'   => array(
85 85
 					'id' => array(
86
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
86
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
87 87
 						'type'        => 'integer',
88 88
 					),
89 89
 				),
90 90
 				array(
91 91
 					'methods'             => WP_REST_Server::READABLE,
92
-					'callback'            => array( $this, 'get_item' ),
93
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
92
+					'callback'            => array($this, 'get_item'),
93
+					'permission_callback' => array($this, 'get_item_permissions_check'),
94 94
 					'args'                => array(
95 95
 						'context' => $this->get_context_param(
96 96
 							array(
@@ -101,23 +101,23 @@  discard block
 block discarded – undo
101 101
 				),
102 102
 				array(
103 103
 					'methods'             => WP_REST_Server::EDITABLE,
104
-					'callback'            => array( $this, 'update_item' ),
105
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
106
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
104
+					'callback'            => array($this, 'update_item'),
105
+					'permission_callback' => array($this, 'update_item_permissions_check'),
106
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
107 107
 				),
108 108
 				array(
109 109
 					'methods'             => WP_REST_Server::DELETABLE,
110
-					'callback'            => array( $this, 'delete_item' ),
111
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
110
+					'callback'            => array($this, 'delete_item'),
111
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
112 112
 					'args'                => array(
113 113
 						'force' => array(
114 114
 							'default'     => false,
115
-							'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
115
+							'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'),
116 116
 							'type'        => 'boolean',
117 117
 						),
118 118
 					),
119 119
 				),
120
-				'schema' => array( $this, 'get_public_item_schema' ),
120
+				'schema' => array($this, 'get_public_item_schema'),
121 121
 			)
122 122
 		);
123 123
 
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
 			array(
128 128
 				array(
129 129
 					'methods'             => WP_REST_Server::EDITABLE,
130
-					'callback'            => array( $this, 'batch_items' ),
131
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
132
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
130
+					'callback'            => array($this, 'batch_items'),
131
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
132
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
133 133
 				),
134
-				'schema' => array( $this, 'get_public_batch_schema' ),
134
+				'schema' => array($this, 'get_public_batch_schema'),
135 135
 			)
136 136
 		);
137 137
 	}
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 	 * @since  3.0.0
145 145
 	 * @return WC_Data
146 146
 	 */
147
-	protected function get_object( $id ) {
148
-		return wc_get_product( $id );
147
+	protected function get_object($id) {
148
+		return wc_get_product($id);
149 149
 	}
150 150
 
151 151
 	/**
@@ -157,24 +157,24 @@  discard block
 block discarded – undo
157 157
 	 * @since  3.0.0
158 158
 	 * @return WP_REST_Response
159 159
 	 */
160
-	public function prepare_object_for_response( $object, $request ) {
161
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
162
-		$data    = $this->get_product_data( $object, $context );
160
+	public function prepare_object_for_response($object, $request) {
161
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
162
+		$data    = $this->get_product_data($object, $context);
163 163
 
164 164
 		// Add variations to variable products.
165
-		if ( $object->is_type( 'variable' ) && $object->has_child() ) {
165
+		if ($object->is_type('variable') && $object->has_child()) {
166 166
 			$data['variations'] = $object->get_children();
167 167
 		}
168 168
 
169 169
 		// Add grouped products data.
170
-		if ( $object->is_type( 'grouped' ) && $object->has_child() ) {
170
+		if ($object->is_type('grouped') && $object->has_child()) {
171 171
 			$data['grouped_products'] = $object->get_children();
172 172
 		}
173 173
 
174
-		$data     = $this->add_additional_fields_to_object( $data, $request );
175
-		$data     = $this->filter_response_by_context( $data, $context );
176
-		$response = rest_ensure_response( $data );
177
-		$response->add_links( $this->prepare_links( $object, $request ) );
174
+		$data     = $this->add_additional_fields_to_object($data, $request);
175
+		$data     = $this->filter_response_by_context($data, $context);
176
+		$response = rest_ensure_response($data);
177
+		$response->add_links($this->prepare_links($object, $request));
178 178
 
179 179
 		/**
180 180
 		 * Filter the data for a response.
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 		 * @param WC_Data          $object   Object data.
187 187
 		 * @param WP_REST_Request  $request  Request object.
188 188
 		 */
189
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
189
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request);
190 190
 	}
191 191
 
192 192
 	/**
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
 	 * @since  3.0.0
198 198
 	 * @return array
199 199
 	 */
200
-	protected function prepare_objects_query( $request ) {
201
-		$args = parent::prepare_objects_query( $request );
200
+	protected function prepare_objects_query($request) {
201
+		$args = parent::prepare_objects_query($request);
202 202
 
203 203
 		// Set post_status.
204 204
 		$args['post_status'] = $request['status'];
@@ -215,18 +215,18 @@  discard block
 block discarded – undo
215 215
 		);
216 216
 
217 217
 		// Set tax_query for each passed arg.
218
-		foreach ( $taxonomies as $taxonomy => $key ) {
219
-			if ( ! empty( $request[ $key ] ) ) {
218
+		foreach ($taxonomies as $taxonomy => $key) {
219
+			if ( ! empty($request[$key])) {
220 220
 				$tax_query[] = array(
221 221
 					'taxonomy' => $taxonomy,
222 222
 					'field'    => 'term_id',
223
-					'terms'    => $request[ $key ],
223
+					'terms'    => $request[$key],
224 224
 				);
225 225
 			}
226 226
 		}
227 227
 
228 228
 		// Filter product type by slug.
229
-		if ( ! empty( $request['type'] ) ) {
229
+		if ( ! empty($request['type'])) {
230 230
 			$tax_query[] = array(
231 231
 				'taxonomy' => 'product_type',
232 232
 				'field'    => 'slug',
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
 		}
236 236
 
237 237
 		// Filter by attribute and term.
238
-		if ( ! empty( $request['attribute'] ) && ! empty( $request['attribute_term'] ) ) {
239
-			if ( in_array( $request['attribute'], wc_get_attribute_taxonomy_names(), true ) ) {
238
+		if ( ! empty($request['attribute']) && ! empty($request['attribute_term'])) {
239
+			if (in_array($request['attribute'], wc_get_attribute_taxonomy_names(), true)) {
240 240
 				$tax_query[] = array(
241 241
 					'taxonomy' => $request['attribute'],
242 242
 					'field'    => 'term_id',
@@ -245,12 +245,12 @@  discard block
 block discarded – undo
245 245
 			}
246 246
 		}
247 247
 
248
-		if ( ! empty( $tax_query ) ) {
248
+		if ( ! empty($tax_query)) {
249 249
 			$args['tax_query'] = $tax_query; // WPCS: slow query ok.
250 250
 		}
251 251
 
252 252
 		// Filter featured.
253
-		if ( is_bool( $request['featured'] ) ) {
253
+		if (is_bool($request['featured'])) {
254 254
 			$args['tax_query'][] = array(
255 255
 				'taxonomy' => 'product_visibility',
256 256
 				'field'    => 'name',
@@ -260,10 +260,10 @@  discard block
 block discarded – undo
260 260
 		}
261 261
 
262 262
 		// Filter by sku.
263
-		if ( ! empty( $request['sku'] ) ) {
264
-			$skus = explode( ',', $request['sku'] );
263
+		if ( ! empty($request['sku'])) {
264
+			$skus = explode(',', $request['sku']);
265 265
 			// Include the current string as a SKU too.
266
-			if ( 1 < count( $skus ) ) {
266
+			if (1 < count($skus)) {
267 267
 				$skus[] = $request['sku'];
268 268
 			}
269 269
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		}
279 279
 
280 280
 		// Filter by tax class.
281
-		if ( ! empty( $request['tax_class'] ) ) {
281
+		if ( ! empty($request['tax_class'])) {
282 282
 			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
283 283
 				$args,
284 284
 				array(
@@ -289,12 +289,12 @@  discard block
 block discarded – undo
289 289
 		}
290 290
 
291 291
 		// Price filter.
292
-		if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) {
293
-			$args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) );  // WPCS: slow query ok.
292
+		if ( ! empty($request['min_price']) || ! empty($request['max_price'])) {
293
+			$args['meta_query'] = $this->add_meta_query($args, wc_get_min_max_price_meta_query($request)); // WPCS: slow query ok.
294 294
 		}
295 295
 
296 296
 		// Filter product in stock or out of stock.
297
-		if ( is_bool( $request['in_stock'] ) ) {
297
+		if (is_bool($request['in_stock'])) {
298 298
 			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
299 299
 				$args,
300 300
 				array(
@@ -305,19 +305,19 @@  discard block
 block discarded – undo
305 305
 		}
306 306
 
307 307
 		// Filter by on sale products.
308
-		if ( is_bool( $request['on_sale'] ) ) {
308
+		if (is_bool($request['on_sale'])) {
309 309
 			$on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in';
310 310
 			$on_sale_ids = wc_get_product_ids_on_sale();
311 311
 
312 312
 			// Use 0 when there's no on sale products to avoid return all products.
313
-			$on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids;
313
+			$on_sale_ids = empty($on_sale_ids) ? array(0) : $on_sale_ids;
314 314
 
315
-			$args[ $on_sale_key ] += $on_sale_ids;
315
+			$args[$on_sale_key] += $on_sale_ids;
316 316
 		}
317 317
 
318 318
 		// Force the post_type argument, since it's not a user input variable.
319
-		if ( ! empty( $request['sku'] ) ) {
320
-			$args['post_type'] = array( 'product', 'product_variation' );
319
+		if ( ! empty($request['sku'])) {
320
+			$args['post_type'] = array('product', 'product_variation');
321 321
 		} else {
322 322
 			$args['post_type'] = $this->post_type;
323 323
 		}
@@ -332,11 +332,11 @@  discard block
 block discarded – undo
332 332
 	 *
333 333
 	 * @return array
334 334
 	 */
335
-	protected function get_downloads( $product ) {
335
+	protected function get_downloads($product) {
336 336
 		$downloads = array();
337 337
 
338
-		if ( $product->is_downloadable() ) {
339
-			foreach ( $product->get_downloads() as $file_id => $file ) {
338
+		if ($product->is_downloadable()) {
339
+			foreach ($product->get_downloads() as $file_id => $file) {
340 340
 				$downloads[] = array(
341 341
 					'id'   => $file_id, // MD5 hash.
342 342
 					'name' => $file['name'],
@@ -356,10 +356,10 @@  discard block
 block discarded – undo
356 356
 	 *
357 357
 	 * @return array
358 358
 	 */
359
-	protected function get_taxonomy_terms( $product, $taxonomy = 'cat' ) {
359
+	protected function get_taxonomy_terms($product, $taxonomy = 'cat') {
360 360
 		$terms = array();
361 361
 
362
-		foreach ( wc_get_object_terms( $product->get_id(), 'product_' . $taxonomy ) as $term ) {
362
+		foreach (wc_get_object_terms($product->get_id(), 'product_' . $taxonomy) as $term) {
363 363
 			$terms[] = array(
364 364
 				'id'   => $term->term_id,
365 365
 				'name' => $term->name,
@@ -377,54 +377,54 @@  discard block
 block discarded – undo
377 377
 	 *
378 378
 	 * @return array
379 379
 	 */
380
-	protected function get_images( $product ) {
380
+	protected function get_images($product) {
381 381
 		$images         = array();
382 382
 		$attachment_ids = array();
383 383
 
384 384
 		// Add featured image.
385
-		if ( $product->get_image_id() ) {
385
+		if ($product->get_image_id()) {
386 386
 			$attachment_ids[] = $product->get_image_id();
387 387
 		}
388 388
 
389 389
 		// Add gallery images.
390
-		$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() );
390
+		$attachment_ids = array_merge($attachment_ids, $product->get_gallery_image_ids());
391 391
 
392 392
 		// Build image data.
393
-		foreach ( $attachment_ids as $position => $attachment_id ) {
394
-			$attachment_post = get_post( $attachment_id );
395
-			if ( is_null( $attachment_post ) ) {
393
+		foreach ($attachment_ids as $position => $attachment_id) {
394
+			$attachment_post = get_post($attachment_id);
395
+			if (is_null($attachment_post)) {
396 396
 				continue;
397 397
 			}
398 398
 
399
-			$attachment = wp_get_attachment_image_src( $attachment_id, 'full' );
400
-			if ( ! is_array( $attachment ) ) {
399
+			$attachment = wp_get_attachment_image_src($attachment_id, 'full');
400
+			if ( ! is_array($attachment)) {
401 401
 				continue;
402 402
 			}
403 403
 
404 404
 			$images[] = array(
405 405
 				'id'                => (int) $attachment_id,
406
-				'date_created'      => wc_rest_prepare_date_response( $attachment_post->post_date, false ),
407
-				'date_created_gmt'  => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ),
408
-				'date_modified'     => wc_rest_prepare_date_response( $attachment_post->post_modified, false ),
409
-				'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ),
410
-				'src'               => current( $attachment ),
411
-				'name'              => get_the_title( $attachment_id ),
412
-				'alt'               => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
406
+				'date_created'      => wc_rest_prepare_date_response($attachment_post->post_date, false),
407
+				'date_created_gmt'  => wc_rest_prepare_date_response(strtotime($attachment_post->post_date_gmt)),
408
+				'date_modified'     => wc_rest_prepare_date_response($attachment_post->post_modified, false),
409
+				'date_modified_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_modified_gmt)),
410
+				'src'               => current($attachment),
411
+				'name'              => get_the_title($attachment_id),
412
+				'alt'               => get_post_meta($attachment_id, '_wp_attachment_image_alt', true),
413 413
 				'position'          => (int) $position,
414 414
 			);
415 415
 		}
416 416
 
417 417
 		// Set a placeholder image if the product has no images set.
418
-		if ( empty( $images ) ) {
418
+		if (empty($images)) {
419 419
 			$images[] = array(
420 420
 				'id'                => 0,
421
-				'date_created'      => wc_rest_prepare_date_response( current_time( 'mysql' ), false ), // Default to now.
422
-				'date_created_gmt'  => wc_rest_prepare_date_response( current_time( 'timestamp', true ) ), // Default to now.
423
-				'date_modified'     => wc_rest_prepare_date_response( current_time( 'mysql' ), false ),
424
-				'date_modified_gmt' => wc_rest_prepare_date_response( current_time( 'timestamp', true ) ),
421
+				'date_created'      => wc_rest_prepare_date_response(current_time('mysql'), false), // Default to now.
422
+				'date_created_gmt'  => wc_rest_prepare_date_response(current_time('timestamp', true)), // Default to now.
423
+				'date_modified'     => wc_rest_prepare_date_response(current_time('mysql'), false),
424
+				'date_modified_gmt' => wc_rest_prepare_date_response(current_time('timestamp', true)),
425 425
 				'src'               => wc_placeholder_img_src(),
426
-				'name'              => __( 'Placeholder', 'woocommerce' ),
427
-				'alt'               => __( 'Placeholder', 'woocommerce' ),
426
+				'name'              => __('Placeholder', 'woocommerce'),
427
+				'alt'               => __('Placeholder', 'woocommerce'),
428 428
 				'position'          => 0,
429 429
 			);
430 430
 		}
@@ -440,9 +440,9 @@  discard block
 block discarded – undo
440 440
 	 * @deprecated 3.0.0
441 441
 	 * @return     string
442 442
 	 */
443
-	protected function get_attribute_taxonomy_label( $name ) {
444
-		$tax    = get_taxonomy( $name );
445
-		$labels = get_taxonomy_labels( $tax );
443
+	protected function get_attribute_taxonomy_label($name) {
444
+		$tax    = get_taxonomy($name);
445
+		$labels = get_taxonomy_labels($tax);
446 446
 
447 447
 		return $labels->singular_name;
448 448
 	}
@@ -456,25 +456,25 @@  discard block
 block discarded – undo
456 456
 	 * @since  3.0.0
457 457
 	 * @return string
458 458
 	 */
459
-	protected function get_attribute_taxonomy_name( $slug, $product ) {
459
+	protected function get_attribute_taxonomy_name($slug, $product) {
460 460
 		// Format slug so it matches attributes of the product.
461
-		$slug       = wc_attribute_taxonomy_slug( $slug );
461
+		$slug       = wc_attribute_taxonomy_slug($slug);
462 462
 		$attributes = $product->get_attributes();
463 463
 		$attribute  = false;
464 464
 
465 465
 		// pa_ attributes.
466
-		if ( isset( $attributes[ wc_attribute_taxonomy_name( $slug ) ] ) ) {
467
-			$attribute = $attributes[ wc_attribute_taxonomy_name( $slug ) ];
468
-		} elseif ( isset( $attributes[ $slug ] ) ) {
469
-			$attribute = $attributes[ $slug ];
466
+		if (isset($attributes[wc_attribute_taxonomy_name($slug)])) {
467
+			$attribute = $attributes[wc_attribute_taxonomy_name($slug)];
468
+		} elseif (isset($attributes[$slug])) {
469
+			$attribute = $attributes[$slug];
470 470
 		}
471 471
 
472
-		if ( ! $attribute ) {
472
+		if ( ! $attribute) {
473 473
 			return $slug;
474 474
 		}
475 475
 
476 476
 		// Taxonomy attribute name.
477
-		if ( $attribute->is_taxonomy() ) {
477
+		if ($attribute->is_taxonomy()) {
478 478
 			$taxonomy = $attribute->get_taxonomy_object();
479 479
 			return $taxonomy->attribute_label;
480 480
 		}
@@ -490,21 +490,21 @@  discard block
 block discarded – undo
490 490
 	 *
491 491
 	 * @return array
492 492
 	 */
493
-	protected function get_default_attributes( $product ) {
493
+	protected function get_default_attributes($product) {
494 494
 		$default = array();
495 495
 
496
-		if ( $product->is_type( 'variable' ) ) {
497
-			foreach ( array_filter( (array) $product->get_default_attributes(), 'strlen' ) as $key => $value ) {
498
-				if ( 0 === strpos( $key, 'pa_' ) ) {
496
+		if ($product->is_type('variable')) {
497
+			foreach (array_filter((array) $product->get_default_attributes(), 'strlen') as $key => $value) {
498
+				if (0 === strpos($key, 'pa_')) {
499 499
 					$default[] = array(
500
-						'id'     => wc_attribute_taxonomy_id_by_name( $key ),
501
-						'name'   => $this->get_attribute_taxonomy_name( $key, $product ),
500
+						'id'     => wc_attribute_taxonomy_id_by_name($key),
501
+						'name'   => $this->get_attribute_taxonomy_name($key, $product),
502 502
 						'option' => $value,
503 503
 					);
504 504
 				} else {
505 505
 					$default[] = array(
506 506
 						'id'     => 0,
507
-						'name'   => $this->get_attribute_taxonomy_name( $key, $product ),
507
+						'name'   => $this->get_attribute_taxonomy_name($key, $product),
508 508
 						'option' => $value,
509 509
 					);
510 510
 				}
@@ -522,8 +522,8 @@  discard block
 block discarded – undo
522 522
 	 *
523 523
 	 * @return array
524 524
 	 */
525
-	protected function get_attribute_options( $product_id, $attribute ) {
526
-		if ( isset( $attribute['is_taxonomy'] ) && $attribute['is_taxonomy'] ) {
525
+	protected function get_attribute_options($product_id, $attribute) {
526
+		if (isset($attribute['is_taxonomy']) && $attribute['is_taxonomy']) {
527 527
 			return wc_get_product_terms(
528 528
 				$product_id,
529 529
 				$attribute['name'],
@@ -531,8 +531,8 @@  discard block
 block discarded – undo
531 531
 					'fields' => 'names',
532 532
 				)
533 533
 			);
534
-		} elseif ( isset( $attribute['value'] ) ) {
535
-			return array_map( 'trim', explode( '|', $attribute['value'] ) );
534
+		} elseif (isset($attribute['value'])) {
535
+			return array_map('trim', explode('|', $attribute['value']));
536 536
 		}
537 537
 
538 538
 		return array();
@@ -545,43 +545,43 @@  discard block
 block discarded – undo
545 545
 	 *
546 546
 	 * @return array
547 547
 	 */
548
-	protected function get_attributes( $product ) {
548
+	protected function get_attributes($product) {
549 549
 		$attributes = array();
550 550
 
551
-		if ( $product->is_type( 'variation' ) ) {
552
-			$_product = wc_get_product( $product->get_parent_id() );
553
-			foreach ( $product->get_variation_attributes() as $attribute_name => $attribute ) {
554
-				$name = str_replace( 'attribute_', '', $attribute_name );
551
+		if ($product->is_type('variation')) {
552
+			$_product = wc_get_product($product->get_parent_id());
553
+			foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
554
+				$name = str_replace('attribute_', '', $attribute_name);
555 555
 
556
-				if ( empty( $attribute ) && '0' !== $attribute ) {
556
+				if (empty($attribute) && '0' !== $attribute) {
557 557
 					continue;
558 558
 				}
559 559
 
560 560
 				// Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`.
561
-				if ( 0 === strpos( $attribute_name, 'attribute_pa_' ) ) {
562
-					$option_term  = get_term_by( 'slug', $attribute, $name );
561
+				if (0 === strpos($attribute_name, 'attribute_pa_')) {
562
+					$option_term  = get_term_by('slug', $attribute, $name);
563 563
 					$attributes[] = array(
564
-						'id'     => wc_attribute_taxonomy_id_by_name( $name ),
565
-						'name'   => $this->get_attribute_taxonomy_name( $name, $_product ),
566
-						'option' => $option_term && ! is_wp_error( $option_term ) ? $option_term->name : $attribute,
564
+						'id'     => wc_attribute_taxonomy_id_by_name($name),
565
+						'name'   => $this->get_attribute_taxonomy_name($name, $_product),
566
+						'option' => $option_term && ! is_wp_error($option_term) ? $option_term->name : $attribute,
567 567
 					);
568 568
 				} else {
569 569
 					$attributes[] = array(
570 570
 						'id'     => 0,
571
-						'name'   => $this->get_attribute_taxonomy_name( $name, $_product ),
571
+						'name'   => $this->get_attribute_taxonomy_name($name, $_product),
572 572
 						'option' => $attribute,
573 573
 					);
574 574
 				}
575 575
 			}
576 576
 		} else {
577
-			foreach ( $product->get_attributes() as $attribute ) {
577
+			foreach ($product->get_attributes() as $attribute) {
578 578
 				$attributes[] = array(
579
-					'id'        => $attribute['is_taxonomy'] ? wc_attribute_taxonomy_id_by_name( $attribute['name'] ) : 0,
580
-					'name'      => $this->get_attribute_taxonomy_name( $attribute['name'], $product ),
579
+					'id'        => $attribute['is_taxonomy'] ? wc_attribute_taxonomy_id_by_name($attribute['name']) : 0,
580
+					'name'      => $this->get_attribute_taxonomy_name($attribute['name'], $product),
581 581
 					'position'  => (int) $attribute['position'],
582 582
 					'visible'   => (bool) $attribute['is_visible'],
583 583
 					'variation' => (bool) $attribute['is_variation'],
584
-					'options'   => $this->get_attribute_options( $product->get_id(), $attribute ),
584
+					'options'   => $this->get_attribute_options($product->get_id(), $attribute),
585 585
 				);
586 586
 			}
587 587
 		}
@@ -598,76 +598,76 @@  discard block
 block discarded – undo
598 598
 	 *
599 599
 	 * @return array
600 600
 	 */
601
-	protected function get_product_data( $product, $context = 'view' ) {
601
+	protected function get_product_data($product, $context = 'view') {
602 602
 		$data = array(
603 603
 			'id'                    => $product->get_id(),
604
-			'name'                  => $product->get_name( $context ),
605
-			'slug'                  => $product->get_slug( $context ),
604
+			'name'                  => $product->get_name($context),
605
+			'slug'                  => $product->get_slug($context),
606 606
 			'permalink'             => $product->get_permalink(),
607
-			'date_created'          => wc_rest_prepare_date_response( $product->get_date_created( $context ), false ),
608
-			'date_created_gmt'      => wc_rest_prepare_date_response( $product->get_date_created( $context ) ),
609
-			'date_modified'         => wc_rest_prepare_date_response( $product->get_date_modified( $context ), false ),
610
-			'date_modified_gmt'     => wc_rest_prepare_date_response( $product->get_date_modified( $context ) ),
607
+			'date_created'          => wc_rest_prepare_date_response($product->get_date_created($context), false),
608
+			'date_created_gmt'      => wc_rest_prepare_date_response($product->get_date_created($context)),
609
+			'date_modified'         => wc_rest_prepare_date_response($product->get_date_modified($context), false),
610
+			'date_modified_gmt'     => wc_rest_prepare_date_response($product->get_date_modified($context)),
611 611
 			'type'                  => $product->get_type(),
612
-			'status'                => $product->get_status( $context ),
612
+			'status'                => $product->get_status($context),
613 613
 			'featured'              => $product->is_featured(),
614
-			'catalog_visibility'    => $product->get_catalog_visibility( $context ),
615
-			'description'           => 'view' === $context ? wpautop( do_shortcode( $product->get_description() ) ) : $product->get_description( $context ),
616
-			'short_description'     => 'view' === $context ? apply_filters( 'woocommerce_short_description', $product->get_short_description() ) : $product->get_short_description( $context ),
617
-			'sku'                   => $product->get_sku( $context ),
618
-			'price'                 => $product->get_price( $context ),
619
-			'regular_price'         => $product->get_regular_price( $context ),
620
-			'sale_price'            => $product->get_sale_price( $context ) ? $product->get_sale_price( $context ) : '',
621
-			'date_on_sale_from'     => wc_rest_prepare_date_response( $product->get_date_on_sale_from( $context ), false ),
622
-			'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $product->get_date_on_sale_from( $context ) ),
623
-			'date_on_sale_to'       => wc_rest_prepare_date_response( $product->get_date_on_sale_to( $context ), false ),
624
-			'date_on_sale_to_gmt'   => wc_rest_prepare_date_response( $product->get_date_on_sale_to( $context ) ),
614
+			'catalog_visibility'    => $product->get_catalog_visibility($context),
615
+			'description'           => 'view' === $context ? wpautop(do_shortcode($product->get_description())) : $product->get_description($context),
616
+			'short_description'     => 'view' === $context ? apply_filters('woocommerce_short_description', $product->get_short_description()) : $product->get_short_description($context),
617
+			'sku'                   => $product->get_sku($context),
618
+			'price'                 => $product->get_price($context),
619
+			'regular_price'         => $product->get_regular_price($context),
620
+			'sale_price'            => $product->get_sale_price($context) ? $product->get_sale_price($context) : '',
621
+			'date_on_sale_from'     => wc_rest_prepare_date_response($product->get_date_on_sale_from($context), false),
622
+			'date_on_sale_from_gmt' => wc_rest_prepare_date_response($product->get_date_on_sale_from($context)),
623
+			'date_on_sale_to'       => wc_rest_prepare_date_response($product->get_date_on_sale_to($context), false),
624
+			'date_on_sale_to_gmt'   => wc_rest_prepare_date_response($product->get_date_on_sale_to($context)),
625 625
 			'price_html'            => $product->get_price_html(),
626
-			'on_sale'               => $product->is_on_sale( $context ),
626
+			'on_sale'               => $product->is_on_sale($context),
627 627
 			'purchasable'           => $product->is_purchasable(),
628
-			'total_sales'           => $product->get_total_sales( $context ),
628
+			'total_sales'           => $product->get_total_sales($context),
629 629
 			'virtual'               => $product->is_virtual(),
630 630
 			'downloadable'          => $product->is_downloadable(),
631
-			'downloads'             => $this->get_downloads( $product ),
632
-			'download_limit'        => $product->get_download_limit( $context ),
633
-			'download_expiry'       => $product->get_download_expiry( $context ),
634
-			'external_url'          => $product->is_type( 'external' ) ? $product->get_product_url( $context ) : '',
635
-			'button_text'           => $product->is_type( 'external' ) ? $product->get_button_text( $context ) : '',
636
-			'tax_status'            => $product->get_tax_status( $context ),
637
-			'tax_class'             => $product->get_tax_class( $context ),
631
+			'downloads'             => $this->get_downloads($product),
632
+			'download_limit'        => $product->get_download_limit($context),
633
+			'download_expiry'       => $product->get_download_expiry($context),
634
+			'external_url'          => $product->is_type('external') ? $product->get_product_url($context) : '',
635
+			'button_text'           => $product->is_type('external') ? $product->get_button_text($context) : '',
636
+			'tax_status'            => $product->get_tax_status($context),
637
+			'tax_class'             => $product->get_tax_class($context),
638 638
 			'manage_stock'          => $product->managing_stock(),
639
-			'stock_quantity'        => $product->get_stock_quantity( $context ),
639
+			'stock_quantity'        => $product->get_stock_quantity($context),
640 640
 			'in_stock'              => $product->is_in_stock(),
641
-			'backorders'            => $product->get_backorders( $context ),
641
+			'backorders'            => $product->get_backorders($context),
642 642
 			'backorders_allowed'    => $product->backorders_allowed(),
643 643
 			'backordered'           => $product->is_on_backorder(),
644 644
 			'sold_individually'     => $product->is_sold_individually(),
645
-			'weight'                => $product->get_weight( $context ),
645
+			'weight'                => $product->get_weight($context),
646 646
 			'dimensions'            => array(
647
-				'length' => $product->get_length( $context ),
648
-				'width'  => $product->get_width( $context ),
649
-				'height' => $product->get_height( $context ),
647
+				'length' => $product->get_length($context),
648
+				'width'  => $product->get_width($context),
649
+				'height' => $product->get_height($context),
650 650
 			),
651 651
 			'shipping_required'     => $product->needs_shipping(),
652 652
 			'shipping_taxable'      => $product->is_shipping_taxable(),
653 653
 			'shipping_class'        => $product->get_shipping_class(),
654
-			'shipping_class_id'     => $product->get_shipping_class_id( $context ),
655
-			'reviews_allowed'       => $product->get_reviews_allowed( $context ),
656
-			'average_rating'        => 'view' === $context ? wc_format_decimal( $product->get_average_rating(), 2 ) : $product->get_average_rating( $context ),
654
+			'shipping_class_id'     => $product->get_shipping_class_id($context),
655
+			'reviews_allowed'       => $product->get_reviews_allowed($context),
656
+			'average_rating'        => 'view' === $context ? wc_format_decimal($product->get_average_rating(), 2) : $product->get_average_rating($context),
657 657
 			'rating_count'          => $product->get_rating_count(),
658
-			'related_ids'           => array_map( 'absint', array_values( wc_get_related_products( $product->get_id() ) ) ),
659
-			'upsell_ids'            => array_map( 'absint', $product->get_upsell_ids( $context ) ),
660
-			'cross_sell_ids'        => array_map( 'absint', $product->get_cross_sell_ids( $context ) ),
661
-			'parent_id'             => $product->get_parent_id( $context ),
662
-			'purchase_note'         => 'view' === $context ? wpautop( do_shortcode( wp_kses_post( $product->get_purchase_note() ) ) ) : $product->get_purchase_note( $context ),
663
-			'categories'            => $this->get_taxonomy_terms( $product ),
664
-			'tags'                  => $this->get_taxonomy_terms( $product, 'tag' ),
665
-			'images'                => $this->get_images( $product ),
666
-			'attributes'            => $this->get_attributes( $product ),
667
-			'default_attributes'    => $this->get_default_attributes( $product ),
658
+			'related_ids'           => array_map('absint', array_values(wc_get_related_products($product->get_id()))),
659
+			'upsell_ids'            => array_map('absint', $product->get_upsell_ids($context)),
660
+			'cross_sell_ids'        => array_map('absint', $product->get_cross_sell_ids($context)),
661
+			'parent_id'             => $product->get_parent_id($context),
662
+			'purchase_note'         => 'view' === $context ? wpautop(do_shortcode(wp_kses_post($product->get_purchase_note()))) : $product->get_purchase_note($context),
663
+			'categories'            => $this->get_taxonomy_terms($product),
664
+			'tags'                  => $this->get_taxonomy_terms($product, 'tag'),
665
+			'images'                => $this->get_images($product),
666
+			'attributes'            => $this->get_attributes($product),
667
+			'default_attributes'    => $this->get_default_attributes($product),
668 668
 			'variations'            => array(),
669 669
 			'grouped_products'      => array(),
670
-			'menu_order'            => $product->get_menu_order( $context ),
670
+			'menu_order'            => $product->get_menu_order($context),
671 671
 			'meta_data'             => $product->get_meta_data(),
672 672
 		);
673 673
 
@@ -682,19 +682,19 @@  discard block
 block discarded – undo
682 682
 	 *
683 683
 	 * @return array                   Links for the given post.
684 684
 	 */
685
-	protected function prepare_links( $object, $request ) {
685
+	protected function prepare_links($object, $request) {
686 686
 		$links = array(
687 687
 			'self'       => array(
688
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ),  // @codingStandardsIgnoreLine.
688
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())), // @codingStandardsIgnoreLine.
689 689
 			),
690 690
 			'collection' => array(
691
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),  // @codingStandardsIgnoreLine.
691
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), // @codingStandardsIgnoreLine.
692 692
 			),
693 693
 		);
694 694
 
695
-		if ( $object->get_parent_id() ) {
695
+		if ($object->get_parent_id()) {
696 696
 			$links['up'] = array(
697
-				'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $object->get_parent_id() ) ),  // @codingStandardsIgnoreLine.
697
+				'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $object->get_parent_id())), // @codingStandardsIgnoreLine.
698 698
 			);
699 699
 		}
700 700
 
@@ -709,28 +709,28 @@  discard block
 block discarded – undo
709 709
 	 *
710 710
 	 * @return WP_Error|WC_Data
711 711
 	 */
712
-	protected function prepare_object_for_database( $request, $creating = false ) {
713
-		$id = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
712
+	protected function prepare_object_for_database($request, $creating = false) {
713
+		$id = isset($request['id']) ? absint($request['id']) : 0;
714 714
 
715 715
 		// Type is the most important part here because we need to be using the correct class and methods.
716
-		if ( isset( $request['type'] ) ) {
717
-			$classname = WC_Product_Factory::get_classname_from_product_type( $request['type'] );
716
+		if (isset($request['type'])) {
717
+			$classname = WC_Product_Factory::get_classname_from_product_type($request['type']);
718 718
 
719
-			if ( ! class_exists( $classname ) ) {
719
+			if ( ! class_exists($classname)) {
720 720
 				$classname = 'WC_Product_Simple';
721 721
 			}
722 722
 
723
-			$product = new $classname( $id );
724
-		} elseif ( isset( $request['id'] ) ) {
725
-			$product = wc_get_product( $id );
723
+			$product = new $classname($id);
724
+		} elseif (isset($request['id'])) {
725
+			$product = wc_get_product($id);
726 726
 		} else {
727 727
 			$product = new WC_Product_Simple();
728 728
 		}
729 729
 
730
-		if ( 'variation' === $product->get_type() ) {
730
+		if ('variation' === $product->get_type()) {
731 731
 			return new WP_Error(
732 732
 				"woocommerce_rest_invalid_{$this->post_type}_id",
733
-				__( 'To manipulate product variations you should use the /products/&lt;product_id&gt;/variations/&lt;id&gt; endpoint.', 'woocommerce' ),
733
+				__('To manipulate product variations you should use the /products/&lt;product_id&gt;/variations/&lt;id&gt; endpoint.', 'woocommerce'),
734 734
 				array(
735 735
 					'status' => 404,
736 736
 				)
@@ -738,338 +738,338 @@  discard block
 block discarded – undo
738 738
 		}
739 739
 
740 740
 		// Post title.
741
-		if ( isset( $request['name'] ) ) {
742
-			$product->set_name( wp_filter_post_kses( $request['name'] ) );
741
+		if (isset($request['name'])) {
742
+			$product->set_name(wp_filter_post_kses($request['name']));
743 743
 		}
744 744
 
745 745
 		// Post content.
746
-		if ( isset( $request['description'] ) ) {
747
-			$product->set_description( wp_filter_post_kses( $request['description'] ) );
746
+		if (isset($request['description'])) {
747
+			$product->set_description(wp_filter_post_kses($request['description']));
748 748
 		}
749 749
 
750 750
 		// Post excerpt.
751
-		if ( isset( $request['short_description'] ) ) {
752
-			$product->set_short_description( wp_filter_post_kses( $request['short_description'] ) );
751
+		if (isset($request['short_description'])) {
752
+			$product->set_short_description(wp_filter_post_kses($request['short_description']));
753 753
 		}
754 754
 
755 755
 		// Post status.
756
-		if ( isset( $request['status'] ) ) {
757
-			$product->set_status( get_post_status_object( $request['status'] ) ? $request['status'] : 'draft' );
756
+		if (isset($request['status'])) {
757
+			$product->set_status(get_post_status_object($request['status']) ? $request['status'] : 'draft');
758 758
 		}
759 759
 
760 760
 		// Post slug.
761
-		if ( isset( $request['slug'] ) ) {
762
-			$product->set_slug( $request['slug'] );
761
+		if (isset($request['slug'])) {
762
+			$product->set_slug($request['slug']);
763 763
 		}
764 764
 
765 765
 		// Menu order.
766
-		if ( isset( $request['menu_order'] ) ) {
767
-			$product->set_menu_order( $request['menu_order'] );
766
+		if (isset($request['menu_order'])) {
767
+			$product->set_menu_order($request['menu_order']);
768 768
 		}
769 769
 
770 770
 		// Comment status.
771
-		if ( isset( $request['reviews_allowed'] ) ) {
772
-			$product->set_reviews_allowed( $request['reviews_allowed'] );
771
+		if (isset($request['reviews_allowed'])) {
772
+			$product->set_reviews_allowed($request['reviews_allowed']);
773 773
 		}
774 774
 
775 775
 		// Virtual.
776
-		if ( isset( $request['virtual'] ) ) {
777
-			$product->set_virtual( $request['virtual'] );
776
+		if (isset($request['virtual'])) {
777
+			$product->set_virtual($request['virtual']);
778 778
 		}
779 779
 
780 780
 		// Tax status.
781
-		if ( isset( $request['tax_status'] ) ) {
782
-			$product->set_tax_status( $request['tax_status'] );
781
+		if (isset($request['tax_status'])) {
782
+			$product->set_tax_status($request['tax_status']);
783 783
 		}
784 784
 
785 785
 		// Tax Class.
786
-		if ( isset( $request['tax_class'] ) ) {
787
-			$product->set_tax_class( $request['tax_class'] );
786
+		if (isset($request['tax_class'])) {
787
+			$product->set_tax_class($request['tax_class']);
788 788
 		}
789 789
 
790 790
 		// Catalog Visibility.
791
-		if ( isset( $request['catalog_visibility'] ) ) {
792
-			$product->set_catalog_visibility( $request['catalog_visibility'] );
791
+		if (isset($request['catalog_visibility'])) {
792
+			$product->set_catalog_visibility($request['catalog_visibility']);
793 793
 		}
794 794
 
795 795
 		// Purchase Note.
796
-		if ( isset( $request['purchase_note'] ) ) {
797
-			$product->set_purchase_note( wp_kses_post( wp_unslash( $request['purchase_note'] ) ) );
796
+		if (isset($request['purchase_note'])) {
797
+			$product->set_purchase_note(wp_kses_post(wp_unslash($request['purchase_note'])));
798 798
 		}
799 799
 
800 800
 		// Featured Product.
801
-		if ( isset( $request['featured'] ) ) {
802
-			$product->set_featured( $request['featured'] );
801
+		if (isset($request['featured'])) {
802
+			$product->set_featured($request['featured']);
803 803
 		}
804 804
 
805 805
 		// Shipping data.
806
-		$product = $this->save_product_shipping_data( $product, $request );
806
+		$product = $this->save_product_shipping_data($product, $request);
807 807
 
808 808
 		// SKU.
809
-		if ( isset( $request['sku'] ) ) {
810
-			$product->set_sku( wc_clean( $request['sku'] ) );
809
+		if (isset($request['sku'])) {
810
+			$product->set_sku(wc_clean($request['sku']));
811 811
 		}
812 812
 
813 813
 		// Attributes.
814
-		if ( isset( $request['attributes'] ) ) {
814
+		if (isset($request['attributes'])) {
815 815
 			$attributes = array();
816 816
 
817
-			foreach ( $request['attributes'] as $attribute ) {
817
+			foreach ($request['attributes'] as $attribute) {
818 818
 				$attribute_id   = 0;
819 819
 				$attribute_name = '';
820 820
 
821 821
 				// Check ID for global attributes or name for product attributes.
822
-				if ( ! empty( $attribute['id'] ) ) {
823
-					$attribute_id   = absint( $attribute['id'] );
824
-					$attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id );
825
-				} elseif ( ! empty( $attribute['name'] ) ) {
826
-					$attribute_name = wc_clean( $attribute['name'] );
822
+				if ( ! empty($attribute['id'])) {
823
+					$attribute_id   = absint($attribute['id']);
824
+					$attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
825
+				} elseif ( ! empty($attribute['name'])) {
826
+					$attribute_name = wc_clean($attribute['name']);
827 827
 				}
828 828
 
829
-				if ( ! $attribute_id && ! $attribute_name ) {
829
+				if ( ! $attribute_id && ! $attribute_name) {
830 830
 					continue;
831 831
 				}
832 832
 
833
-				if ( $attribute_id ) {
833
+				if ($attribute_id) {
834 834
 
835
-					if ( isset( $attribute['options'] ) ) {
835
+					if (isset($attribute['options'])) {
836 836
 						$options = $attribute['options'];
837 837
 
838
-						if ( ! is_array( $attribute['options'] ) ) {
838
+						if ( ! is_array($attribute['options'])) {
839 839
 							// Text based attributes - Posted values are term names.
840
-							$options = explode( WC_DELIMITER, $options );
840
+							$options = explode(WC_DELIMITER, $options);
841 841
 						}
842 842
 
843
-						$values = array_map( 'wc_sanitize_term_text_based', $options );
844
-						$values = array_filter( $values, 'strlen' );
843
+						$values = array_map('wc_sanitize_term_text_based', $options);
844
+						$values = array_filter($values, 'strlen');
845 845
 					} else {
846 846
 						$values = array();
847 847
 					}
848 848
 
849
-					if ( ! empty( $values ) ) {
849
+					if ( ! empty($values)) {
850 850
 						// Add attribute to array, but don't set values.
851 851
 						$attribute_object = new WC_Product_Attribute();
852
-						$attribute_object->set_id( $attribute_id );
853
-						$attribute_object->set_name( $attribute_name );
854
-						$attribute_object->set_options( $values );
855
-						$attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' );
856
-						$attribute_object->set_visible( ( isset( $attribute['visible'] ) && $attribute['visible'] ) ? 1 : 0 );
857
-						$attribute_object->set_variation( ( isset( $attribute['variation'] ) && $attribute['variation'] ) ? 1 : 0 );
852
+						$attribute_object->set_id($attribute_id);
853
+						$attribute_object->set_name($attribute_name);
854
+						$attribute_object->set_options($values);
855
+						$attribute_object->set_position(isset($attribute['position']) ? (string) absint($attribute['position']) : '0');
856
+						$attribute_object->set_visible((isset($attribute['visible']) && $attribute['visible']) ? 1 : 0);
857
+						$attribute_object->set_variation((isset($attribute['variation']) && $attribute['variation']) ? 1 : 0);
858 858
 						$attributes[] = $attribute_object;
859 859
 					}
860
-				} elseif ( isset( $attribute['options'] ) ) {
860
+				} elseif (isset($attribute['options'])) {
861 861
 					// Custom attribute - Add attribute to array and set the values.
862
-					if ( is_array( $attribute['options'] ) ) {
862
+					if (is_array($attribute['options'])) {
863 863
 						$values = $attribute['options'];
864 864
 					} else {
865
-						$values = explode( WC_DELIMITER, $attribute['options'] );
865
+						$values = explode(WC_DELIMITER, $attribute['options']);
866 866
 					}
867 867
 					$attribute_object = new WC_Product_Attribute();
868
-					$attribute_object->set_name( $attribute_name );
869
-					$attribute_object->set_options( $values );
870
-					$attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' );
871
-					$attribute_object->set_visible( ( isset( $attribute['visible'] ) && $attribute['visible'] ) ? 1 : 0 );
872
-					$attribute_object->set_variation( ( isset( $attribute['variation'] ) && $attribute['variation'] ) ? 1 : 0 );
868
+					$attribute_object->set_name($attribute_name);
869
+					$attribute_object->set_options($values);
870
+					$attribute_object->set_position(isset($attribute['position']) ? (string) absint($attribute['position']) : '0');
871
+					$attribute_object->set_visible((isset($attribute['visible']) && $attribute['visible']) ? 1 : 0);
872
+					$attribute_object->set_variation((isset($attribute['variation']) && $attribute['variation']) ? 1 : 0);
873 873
 					$attributes[] = $attribute_object;
874 874
 				}
875 875
 			}
876
-			$product->set_attributes( $attributes );
876
+			$product->set_attributes($attributes);
877 877
 		}
878 878
 
879 879
 		// Sales and prices.
880
-		if ( in_array( $product->get_type(), array( 'variable', 'grouped' ), true ) ) {
881
-			$product->set_regular_price( '' );
882
-			$product->set_sale_price( '' );
883
-			$product->set_date_on_sale_to( '' );
884
-			$product->set_date_on_sale_from( '' );
885
-			$product->set_price( '' );
880
+		if (in_array($product->get_type(), array('variable', 'grouped'), true)) {
881
+			$product->set_regular_price('');
882
+			$product->set_sale_price('');
883
+			$product->set_date_on_sale_to('');
884
+			$product->set_date_on_sale_from('');
885
+			$product->set_price('');
886 886
 		} else {
887 887
 			// Regular Price.
888
-			if ( isset( $request['regular_price'] ) ) {
889
-				$product->set_regular_price( $request['regular_price'] );
888
+			if (isset($request['regular_price'])) {
889
+				$product->set_regular_price($request['regular_price']);
890 890
 			}
891 891
 
892 892
 			// Sale Price.
893
-			if ( isset( $request['sale_price'] ) ) {
894
-				$product->set_sale_price( $request['sale_price'] );
893
+			if (isset($request['sale_price'])) {
894
+				$product->set_sale_price($request['sale_price']);
895 895
 			}
896 896
 
897
-			if ( isset( $request['date_on_sale_from'] ) ) {
898
-				$product->set_date_on_sale_from( $request['date_on_sale_from'] );
897
+			if (isset($request['date_on_sale_from'])) {
898
+				$product->set_date_on_sale_from($request['date_on_sale_from']);
899 899
 			}
900 900
 
901
-			if ( isset( $request['date_on_sale_from_gmt'] ) ) {
902
-				$product->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null );
901
+			if (isset($request['date_on_sale_from_gmt'])) {
902
+				$product->set_date_on_sale_from($request['date_on_sale_from_gmt'] ? strtotime($request['date_on_sale_from_gmt']) : null);
903 903
 			}
904 904
 
905
-			if ( isset( $request['date_on_sale_to'] ) ) {
906
-				$product->set_date_on_sale_to( $request['date_on_sale_to'] );
905
+			if (isset($request['date_on_sale_to'])) {
906
+				$product->set_date_on_sale_to($request['date_on_sale_to']);
907 907
 			}
908 908
 
909
-			if ( isset( $request['date_on_sale_to_gmt'] ) ) {
910
-				$product->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null );
909
+			if (isset($request['date_on_sale_to_gmt'])) {
910
+				$product->set_date_on_sale_to($request['date_on_sale_to_gmt'] ? strtotime($request['date_on_sale_to_gmt']) : null);
911 911
 			}
912 912
 		}
913 913
 
914 914
 		// Product parent ID.
915
-		if ( isset( $request['parent_id'] ) ) {
916
-			$product->set_parent_id( $request['parent_id'] );
915
+		if (isset($request['parent_id'])) {
916
+			$product->set_parent_id($request['parent_id']);
917 917
 		}
918 918
 
919 919
 		// Sold individually.
920
-		if ( isset( $request['sold_individually'] ) ) {
921
-			$product->set_sold_individually( $request['sold_individually'] );
920
+		if (isset($request['sold_individually'])) {
921
+			$product->set_sold_individually($request['sold_individually']);
922 922
 		}
923 923
 
924 924
 		// Stock status.
925
-		if ( isset( $request['in_stock'] ) ) {
925
+		if (isset($request['in_stock'])) {
926 926
 			$stock_status = true === $request['in_stock'] ? 'instock' : 'outofstock';
927 927
 		} else {
928 928
 			$stock_status = $product->get_stock_status();
929 929
 		}
930 930
 
931 931
 		// Stock data.
932
-		if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) {
932
+		if ('yes' === get_option('woocommerce_manage_stock')) {
933 933
 			// Manage stock.
934
-			if ( isset( $request['manage_stock'] ) ) {
935
-				$product->set_manage_stock( $request['manage_stock'] );
934
+			if (isset($request['manage_stock'])) {
935
+				$product->set_manage_stock($request['manage_stock']);
936 936
 			}
937 937
 
938 938
 			// Backorders.
939
-			if ( isset( $request['backorders'] ) ) {
940
-				$product->set_backorders( $request['backorders'] );
939
+			if (isset($request['backorders'])) {
940
+				$product->set_backorders($request['backorders']);
941 941
 			}
942 942
 
943
-			if ( $product->is_type( 'grouped' ) ) {
944
-				$product->set_manage_stock( 'no' );
945
-				$product->set_backorders( 'no' );
946
-				$product->set_stock_quantity( '' );
947
-				$product->set_stock_status( $stock_status );
948
-			} elseif ( $product->is_type( 'external' ) ) {
949
-				$product->set_manage_stock( 'no' );
950
-				$product->set_backorders( 'no' );
951
-				$product->set_stock_quantity( '' );
952
-				$product->set_stock_status( 'instock' );
953
-			} elseif ( $product->get_manage_stock() ) {
943
+			if ($product->is_type('grouped')) {
944
+				$product->set_manage_stock('no');
945
+				$product->set_backorders('no');
946
+				$product->set_stock_quantity('');
947
+				$product->set_stock_status($stock_status);
948
+			} elseif ($product->is_type('external')) {
949
+				$product->set_manage_stock('no');
950
+				$product->set_backorders('no');
951
+				$product->set_stock_quantity('');
952
+				$product->set_stock_status('instock');
953
+			} elseif ($product->get_manage_stock()) {
954 954
 				// Stock status is always determined by children so sync later.
955
-				if ( ! $product->is_type( 'variable' ) ) {
956
-					$product->set_stock_status( $stock_status );
955
+				if ( ! $product->is_type('variable')) {
956
+					$product->set_stock_status($stock_status);
957 957
 				}
958 958
 
959 959
 				// Stock quantity.
960
-				if ( isset( $request['stock_quantity'] ) ) {
961
-					$product->set_stock_quantity( wc_stock_amount( $request['stock_quantity'] ) );
962
-				} elseif ( isset( $request['inventory_delta'] ) ) {
963
-					$stock_quantity  = wc_stock_amount( $product->get_stock_quantity() );
964
-					$stock_quantity += wc_stock_amount( $request['inventory_delta'] );
965
-					$product->set_stock_quantity( wc_stock_amount( $stock_quantity ) );
960
+				if (isset($request['stock_quantity'])) {
961
+					$product->set_stock_quantity(wc_stock_amount($request['stock_quantity']));
962
+				} elseif (isset($request['inventory_delta'])) {
963
+					$stock_quantity  = wc_stock_amount($product->get_stock_quantity());
964
+					$stock_quantity += wc_stock_amount($request['inventory_delta']);
965
+					$product->set_stock_quantity(wc_stock_amount($stock_quantity));
966 966
 				}
967 967
 			} else {
968 968
 				// Don't manage stock.
969
-				$product->set_manage_stock( 'no' );
970
-				$product->set_stock_quantity( '' );
971
-				$product->set_stock_status( $stock_status );
969
+				$product->set_manage_stock('no');
970
+				$product->set_stock_quantity('');
971
+				$product->set_stock_status($stock_status);
972 972
 			}
973
-		} elseif ( ! $product->is_type( 'variable' ) ) {
974
-			$product->set_stock_status( $stock_status );
973
+		} elseif ( ! $product->is_type('variable')) {
974
+			$product->set_stock_status($stock_status);
975 975
 		}
976 976
 
977 977
 		// Upsells.
978
-		if ( isset( $request['upsell_ids'] ) ) {
978
+		if (isset($request['upsell_ids'])) {
979 979
 			$upsells = array();
980 980
 			$ids     = $request['upsell_ids'];
981 981
 
982
-			if ( ! empty( $ids ) ) {
983
-				foreach ( $ids as $id ) {
984
-					if ( $id && $id > 0 ) {
982
+			if ( ! empty($ids)) {
983
+				foreach ($ids as $id) {
984
+					if ($id && $id > 0) {
985 985
 						$upsells[] = $id;
986 986
 					}
987 987
 				}
988 988
 			}
989 989
 
990
-			$product->set_upsell_ids( $upsells );
990
+			$product->set_upsell_ids($upsells);
991 991
 		}
992 992
 
993 993
 		// Cross sells.
994
-		if ( isset( $request['cross_sell_ids'] ) ) {
994
+		if (isset($request['cross_sell_ids'])) {
995 995
 			$crosssells = array();
996 996
 			$ids        = $request['cross_sell_ids'];
997 997
 
998
-			if ( ! empty( $ids ) ) {
999
-				foreach ( $ids as $id ) {
1000
-					if ( $id && $id > 0 ) {
998
+			if ( ! empty($ids)) {
999
+				foreach ($ids as $id) {
1000
+					if ($id && $id > 0) {
1001 1001
 						$crosssells[] = $id;
1002 1002
 					}
1003 1003
 				}
1004 1004
 			}
1005 1005
 
1006
-			$product->set_cross_sell_ids( $crosssells );
1006
+			$product->set_cross_sell_ids($crosssells);
1007 1007
 		}
1008 1008
 
1009 1009
 		// Product categories.
1010
-		if ( isset( $request['categories'] ) && is_array( $request['categories'] ) ) {
1011
-			$product = $this->save_taxonomy_terms( $product, $request['categories'] );
1010
+		if (isset($request['categories']) && is_array($request['categories'])) {
1011
+			$product = $this->save_taxonomy_terms($product, $request['categories']);
1012 1012
 		}
1013 1013
 
1014 1014
 		// Product tags.
1015
-		if ( isset( $request['tags'] ) && is_array( $request['tags'] ) ) {
1016
-			$product = $this->save_taxonomy_terms( $product, $request['tags'], 'tag' );
1015
+		if (isset($request['tags']) && is_array($request['tags'])) {
1016
+			$product = $this->save_taxonomy_terms($product, $request['tags'], 'tag');
1017 1017
 		}
1018 1018
 
1019 1019
 		// Downloadable.
1020
-		if ( isset( $request['downloadable'] ) ) {
1021
-			$product->set_downloadable( $request['downloadable'] );
1020
+		if (isset($request['downloadable'])) {
1021
+			$product->set_downloadable($request['downloadable']);
1022 1022
 		}
1023 1023
 
1024 1024
 		// Downloadable options.
1025
-		if ( $product->get_downloadable() ) {
1025
+		if ($product->get_downloadable()) {
1026 1026
 
1027 1027
 			// Downloadable files.
1028
-			if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) {
1029
-				$product = $this->save_downloadable_files( $product, $request['downloads'] );
1028
+			if (isset($request['downloads']) && is_array($request['downloads'])) {
1029
+				$product = $this->save_downloadable_files($product, $request['downloads']);
1030 1030
 			}
1031 1031
 
1032 1032
 			// Download limit.
1033
-			if ( isset( $request['download_limit'] ) ) {
1034
-				$product->set_download_limit( $request['download_limit'] );
1033
+			if (isset($request['download_limit'])) {
1034
+				$product->set_download_limit($request['download_limit']);
1035 1035
 			}
1036 1036
 
1037 1037
 			// Download expiry.
1038
-			if ( isset( $request['download_expiry'] ) ) {
1039
-				$product->set_download_expiry( $request['download_expiry'] );
1038
+			if (isset($request['download_expiry'])) {
1039
+				$product->set_download_expiry($request['download_expiry']);
1040 1040
 			}
1041 1041
 		}
1042 1042
 
1043 1043
 		// Product url and button text for external products.
1044
-		if ( $product->is_type( 'external' ) ) {
1045
-			if ( isset( $request['external_url'] ) ) {
1046
-				$product->set_product_url( $request['external_url'] );
1044
+		if ($product->is_type('external')) {
1045
+			if (isset($request['external_url'])) {
1046
+				$product->set_product_url($request['external_url']);
1047 1047
 			}
1048 1048
 
1049
-			if ( isset( $request['button_text'] ) ) {
1050
-				$product->set_button_text( $request['button_text'] );
1049
+			if (isset($request['button_text'])) {
1050
+				$product->set_button_text($request['button_text']);
1051 1051
 			}
1052 1052
 		}
1053 1053
 
1054 1054
 		// Save default attributes for variable products.
1055
-		if ( $product->is_type( 'variable' ) ) {
1056
-			$product = $this->save_default_attributes( $product, $request );
1055
+		if ($product->is_type('variable')) {
1056
+			$product = $this->save_default_attributes($product, $request);
1057 1057
 		}
1058 1058
 
1059 1059
 		// Set children for a grouped product.
1060
-		if ( $product->is_type( 'grouped' ) && isset( $request['grouped_products'] ) ) {
1061
-			$product->set_children( $request['grouped_products'] );
1060
+		if ($product->is_type('grouped') && isset($request['grouped_products'])) {
1061
+			$product->set_children($request['grouped_products']);
1062 1062
 		}
1063 1063
 
1064 1064
 		// Check for featured/gallery images, upload it and set it.
1065
-		if ( isset( $request['images'] ) ) {
1066
-			$product = $this->set_product_images( $product, $request['images'] );
1065
+		if (isset($request['images'])) {
1066
+			$product = $this->set_product_images($product, $request['images']);
1067 1067
 		}
1068 1068
 
1069 1069
 		// Allow set meta_data.
1070
-		if ( is_array( $request['meta_data'] ) ) {
1071
-			foreach ( $request['meta_data'] as $meta ) {
1072
-				$product->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
1070
+		if (is_array($request['meta_data'])) {
1071
+			foreach ($request['meta_data'] as $meta) {
1072
+				$product->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
1073 1073
 			}
1074 1074
 		}
1075 1075
 
@@ -1083,7 +1083,7 @@  discard block
 block discarded – undo
1083 1083
 		 * @param WP_REST_Request $request  Request object.
1084 1084
 		 * @param bool            $creating If is creating a new object.
1085 1085
 		 */
1086
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $product, $request, $creating );
1086
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $product, $request, $creating);
1087 1087
 	}
1088 1088
 
1089 1089
 	/**
@@ -1095,43 +1095,43 @@  discard block
 block discarded – undo
1095 1095
 	 * @throws WC_REST_Exception REST API exceptions.
1096 1096
 	 * @return WC_Product
1097 1097
 	 */
1098
-	protected function set_product_images( $product, $images ) {
1099
-		$images = is_array( $images ) ? array_filter( $images ) : array();
1098
+	protected function set_product_images($product, $images) {
1099
+		$images = is_array($images) ? array_filter($images) : array();
1100 1100
 
1101
-		if ( ! empty( $images ) ) {
1101
+		if ( ! empty($images)) {
1102 1102
 			$gallery_positions = array();
1103 1103
 
1104
-			foreach ( $images as $index => $image ) {
1105
-				$attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0;
1104
+			foreach ($images as $index => $image) {
1105
+				$attachment_id = isset($image['id']) ? absint($image['id']) : 0;
1106 1106
 
1107
-				if ( 0 === $attachment_id && isset( $image['src'] ) ) {
1108
-					$upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) );
1107
+				if (0 === $attachment_id && isset($image['src'])) {
1108
+					$upload = wc_rest_upload_image_from_url(esc_url_raw($image['src']));
1109 1109
 
1110
-					if ( is_wp_error( $upload ) ) {
1111
-						if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $product->get_id(), $images ) ) {
1112
-							throw new WC_REST_Exception( 'woocommerce_product_image_upload_error', $upload->get_error_message(), 400 );
1110
+					if (is_wp_error($upload)) {
1111
+						if ( ! apply_filters('woocommerce_rest_suppress_image_upload_error', false, $upload, $product->get_id(), $images)) {
1112
+							throw new WC_REST_Exception('woocommerce_product_image_upload_error', $upload->get_error_message(), 400);
1113 1113
 						} else {
1114 1114
 							continue;
1115 1115
 						}
1116 1116
 					}
1117 1117
 
1118
-					$attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $product->get_id() );
1118
+					$attachment_id = wc_rest_set_uploaded_image_as_attachment($upload, $product->get_id());
1119 1119
 				}
1120 1120
 
1121
-				if ( ! wp_attachment_is_image( $attachment_id ) ) {
1121
+				if ( ! wp_attachment_is_image($attachment_id)) {
1122 1122
 					/* translators: %s: attachment id */
1123
-					throw new WC_REST_Exception( 'woocommerce_product_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 );
1123
+					throw new WC_REST_Exception('woocommerce_product_invalid_image_id', sprintf(__('#%s is an invalid image ID.', 'woocommerce'), $attachment_id), 400);
1124 1124
 				}
1125 1125
 
1126
-				$gallery_positions[ $attachment_id ] = absint( isset( $image['position'] ) ? $image['position'] : $index );
1126
+				$gallery_positions[$attachment_id] = absint(isset($image['position']) ? $image['position'] : $index);
1127 1127
 
1128 1128
 				// Set the image alt if present.
1129
-				if ( ! empty( $image['alt'] ) ) {
1130
-					update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) );
1129
+				if ( ! empty($image['alt'])) {
1130
+					update_post_meta($attachment_id, '_wp_attachment_image_alt', wc_clean($image['alt']));
1131 1131
 				}
1132 1132
 
1133 1133
 				// Set the image name if present.
1134
-				if ( ! empty( $image['name'] ) ) {
1134
+				if ( ! empty($image['name'])) {
1135 1135
 					wp_update_post(
1136 1136
 						array(
1137 1137
 							'ID'         => $attachment_id,
@@ -1141,26 +1141,26 @@  discard block
 block discarded – undo
1141 1141
 				}
1142 1142
 
1143 1143
 				// Set the image source if present, for future reference.
1144
-				if ( ! empty( $image['src'] ) ) {
1145
-					update_post_meta( $attachment_id, '_wc_attachment_source', esc_url_raw( $image['src'] ) );
1144
+				if ( ! empty($image['src'])) {
1145
+					update_post_meta($attachment_id, '_wc_attachment_source', esc_url_raw($image['src']));
1146 1146
 				}
1147 1147
 			}
1148 1148
 
1149 1149
 			// Sort images and get IDs in correct order.
1150
-			asort( $gallery_positions );
1150
+			asort($gallery_positions);
1151 1151
 
1152 1152
 			// Get gallery in correct order.
1153
-			$gallery = array_keys( $gallery_positions );
1153
+			$gallery = array_keys($gallery_positions);
1154 1154
 
1155 1155
 			// Featured image is in position 0.
1156
-			$image_id = array_shift( $gallery );
1156
+			$image_id = array_shift($gallery);
1157 1157
 
1158 1158
 			// Set images.
1159
-			$product->set_image_id( $image_id );
1160
-			$product->set_gallery_image_ids( $gallery );
1159
+			$product->set_image_id($image_id);
1160
+			$product->set_gallery_image_ids($gallery);
1161 1161
 		} else {
1162
-			$product->set_image_id( '' );
1163
-			$product->set_gallery_image_ids( array() );
1162
+			$product->set_image_id('');
1163
+			$product->set_gallery_image_ids(array());
1164 1164
 		}
1165 1165
 
1166 1166
 		return $product;
@@ -1174,39 +1174,39 @@  discard block
 block discarded – undo
1174 1174
 	 *
1175 1175
 	 * @return WC_Product
1176 1176
 	 */
1177
-	protected function save_product_shipping_data( $product, $data ) {
1177
+	protected function save_product_shipping_data($product, $data) {
1178 1178
 		// Virtual.
1179
-		if ( isset( $data['virtual'] ) && true === $data['virtual'] ) {
1180
-			$product->set_weight( '' );
1181
-			$product->set_height( '' );
1182
-			$product->set_length( '' );
1183
-			$product->set_width( '' );
1179
+		if (isset($data['virtual']) && true === $data['virtual']) {
1180
+			$product->set_weight('');
1181
+			$product->set_height('');
1182
+			$product->set_length('');
1183
+			$product->set_width('');
1184 1184
 		} else {
1185
-			if ( isset( $data['weight'] ) ) {
1186
-				$product->set_weight( $data['weight'] );
1185
+			if (isset($data['weight'])) {
1186
+				$product->set_weight($data['weight']);
1187 1187
 			}
1188 1188
 
1189 1189
 			// Height.
1190
-			if ( isset( $data['dimensions']['height'] ) ) {
1191
-				$product->set_height( $data['dimensions']['height'] );
1190
+			if (isset($data['dimensions']['height'])) {
1191
+				$product->set_height($data['dimensions']['height']);
1192 1192
 			}
1193 1193
 
1194 1194
 			// Width.
1195
-			if ( isset( $data['dimensions']['width'] ) ) {
1196
-				$product->set_width( $data['dimensions']['width'] );
1195
+			if (isset($data['dimensions']['width'])) {
1196
+				$product->set_width($data['dimensions']['width']);
1197 1197
 			}
1198 1198
 
1199 1199
 			// Length.
1200
-			if ( isset( $data['dimensions']['length'] ) ) {
1201
-				$product->set_length( $data['dimensions']['length'] );
1200
+			if (isset($data['dimensions']['length'])) {
1201
+				$product->set_length($data['dimensions']['length']);
1202 1202
 			}
1203 1203
 		}
1204 1204
 
1205 1205
 		// Shipping class.
1206
-		if ( isset( $data['shipping_class'] ) ) {
1206
+		if (isset($data['shipping_class'])) {
1207 1207
 			$data_store        = $product->get_data_store();
1208
-			$shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data['shipping_class'] ) );
1209
-			$product->set_shipping_class_id( $shipping_class_id );
1208
+			$shipping_class_id = $data_store->get_shipping_class_id_by_slug(wc_clean($data['shipping_class']));
1209
+			$product->set_shipping_class_id($shipping_class_id);
1210 1210
 		}
1211 1211
 
1212 1212
 		return $product;
@@ -1221,24 +1221,24 @@  discard block
 block discarded – undo
1221 1221
 	 *
1222 1222
 	 * @return WC_Product
1223 1223
 	 */
1224
-	protected function save_downloadable_files( $product, $downloads, $deprecated = 0 ) {
1225
-		if ( $deprecated ) {
1226
-			wc_deprecated_argument( 'variation_id', '3.0', 'save_downloadable_files() not requires a variation_id anymore.' );
1224
+	protected function save_downloadable_files($product, $downloads, $deprecated = 0) {
1225
+		if ($deprecated) {
1226
+			wc_deprecated_argument('variation_id', '3.0', 'save_downloadable_files() not requires a variation_id anymore.');
1227 1227
 		}
1228 1228
 
1229 1229
 		$files = array();
1230
-		foreach ( $downloads as $key => $file ) {
1231
-			if ( empty( $file['file'] ) ) {
1230
+		foreach ($downloads as $key => $file) {
1231
+			if (empty($file['file'])) {
1232 1232
 				continue;
1233 1233
 			}
1234 1234
 
1235 1235
 			$download = new WC_Product_Download();
1236
-			$download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() );
1237
-			$download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) );
1238
-			$download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) );
1236
+			$download->set_id( ! empty($file['id']) ? $file['id'] : wp_generate_uuid4());
1237
+			$download->set_name($file['name'] ? $file['name'] : wc_get_filename_from_url($file['file']));
1238
+			$download->set_file(apply_filters('woocommerce_file_download_path', $file['file'], $product, $key));
1239 1239
 			$files[] = $download;
1240 1240
 		}
1241
-		$product->set_downloads( $files );
1241
+		$product->set_downloads($files);
1242 1242
 
1243 1243
 		return $product;
1244 1244
 	}
@@ -1252,13 +1252,13 @@  discard block
 block discarded – undo
1252 1252
 	 *
1253 1253
 	 * @return WC_Product
1254 1254
 	 */
1255
-	protected function save_taxonomy_terms( $product, $terms, $taxonomy = 'cat' ) {
1256
-		$term_ids = wp_list_pluck( $terms, 'id' );
1255
+	protected function save_taxonomy_terms($product, $terms, $taxonomy = 'cat') {
1256
+		$term_ids = wp_list_pluck($terms, 'id');
1257 1257
 
1258
-		if ( 'cat' === $taxonomy ) {
1259
-			$product->set_category_ids( $term_ids );
1260
-		} elseif ( 'tag' === $taxonomy ) {
1261
-			$product->set_tag_ids( $term_ids );
1258
+		if ('cat' === $taxonomy) {
1259
+			$product->set_category_ids($term_ids);
1260
+		} elseif ('tag' === $taxonomy) {
1261
+			$product->set_tag_ids($term_ids);
1262 1262
 		}
1263 1263
 
1264 1264
 		return $product;
@@ -1273,53 +1273,53 @@  discard block
 block discarded – undo
1273 1273
 	 * @since  3.0.0
1274 1274
 	 * @return WC_Product
1275 1275
 	 */
1276
-	protected function save_default_attributes( $product, $request ) {
1277
-		if ( isset( $request['default_attributes'] ) && is_array( $request['default_attributes'] ) ) {
1276
+	protected function save_default_attributes($product, $request) {
1277
+		if (isset($request['default_attributes']) && is_array($request['default_attributes'])) {
1278 1278
 
1279 1279
 			$attributes         = $product->get_attributes();
1280 1280
 			$default_attributes = array();
1281 1281
 
1282
-			foreach ( $request['default_attributes'] as $attribute ) {
1282
+			foreach ($request['default_attributes'] as $attribute) {
1283 1283
 				$attribute_id   = 0;
1284 1284
 				$attribute_name = '';
1285 1285
 
1286 1286
 				// Check ID for global attributes or name for product attributes.
1287
-				if ( ! empty( $attribute['id'] ) ) {
1288
-					$attribute_id   = absint( $attribute['id'] );
1289
-					$attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id );
1290
-				} elseif ( ! empty( $attribute['name'] ) ) {
1291
-					$attribute_name = sanitize_title( $attribute['name'] );
1287
+				if ( ! empty($attribute['id'])) {
1288
+					$attribute_id   = absint($attribute['id']);
1289
+					$attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
1290
+				} elseif ( ! empty($attribute['name'])) {
1291
+					$attribute_name = sanitize_title($attribute['name']);
1292 1292
 				}
1293 1293
 
1294
-				if ( ! $attribute_id && ! $attribute_name ) {
1294
+				if ( ! $attribute_id && ! $attribute_name) {
1295 1295
 					continue;
1296 1296
 				}
1297 1297
 
1298
-				if ( isset( $attributes[ $attribute_name ] ) ) {
1299
-					$_attribute = $attributes[ $attribute_name ];
1298
+				if (isset($attributes[$attribute_name])) {
1299
+					$_attribute = $attributes[$attribute_name];
1300 1300
 
1301
-					if ( $_attribute['is_variation'] ) {
1302
-						$value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : '';
1301
+					if ($_attribute['is_variation']) {
1302
+						$value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : '';
1303 1303
 
1304
-						if ( ! empty( $_attribute['is_taxonomy'] ) ) {
1304
+						if ( ! empty($_attribute['is_taxonomy'])) {
1305 1305
 							// If dealing with a taxonomy, we need to get the slug from the name posted to the API.
1306
-							$term = get_term_by( 'name', $value, $attribute_name );
1306
+							$term = get_term_by('name', $value, $attribute_name);
1307 1307
 
1308
-							if ( $term && ! is_wp_error( $term ) ) {
1308
+							if ($term && ! is_wp_error($term)) {
1309 1309
 								$value = $term->slug;
1310 1310
 							} else {
1311
-								$value = sanitize_title( $value );
1311
+								$value = sanitize_title($value);
1312 1312
 							}
1313 1313
 						}
1314 1314
 
1315
-						if ( $value ) {
1316
-							$default_attributes[ $attribute_name ] = $value;
1315
+						if ($value) {
1316
+							$default_attributes[$attribute_name] = $value;
1317 1317
 						}
1318 1318
 					}
1319 1319
 				}
1320 1320
 			}
1321 1321
 
1322
-			$product->set_default_attributes( $default_attributes );
1322
+			$product->set_default_attributes($default_attributes);
1323 1323
 		}
1324 1324
 
1325 1325
 		return $product;
@@ -1330,9 +1330,9 @@  discard block
 block discarded – undo
1330 1330
 	 *
1331 1331
 	 * @param WC_Data $object Object data.
1332 1332
 	 */
1333
-	public function clear_transients( $object ) {
1334
-		wc_delete_product_transients( $object->get_id() );
1335
-		wp_cache_delete( 'product-' . $object->get_id(), 'products' );
1333
+	public function clear_transients($object) {
1334
+		wc_delete_product_transients($object->get_id());
1335
+		wp_cache_delete('product-' . $object->get_id(), 'products');
1336 1336
 	}
1337 1337
 
1338 1338
 	/**
@@ -1342,33 +1342,33 @@  discard block
 block discarded – undo
1342 1342
 	 *
1343 1343
 	 * @return WP_REST_Response|WP_Error
1344 1344
 	 */
1345
-	public function delete_item( $request ) {
1345
+	public function delete_item($request) {
1346 1346
 		$id     = (int) $request['id'];
1347 1347
 		$force  = (bool) $request['force'];
1348
-		$object = $this->get_object( (int) $request['id'] );
1348
+		$object = $this->get_object((int) $request['id']);
1349 1349
 		$result = false;
1350 1350
 
1351
-		if ( ! $object || 0 === $object->get_id() ) {
1351
+		if ( ! $object || 0 === $object->get_id()) {
1352 1352
 			return new WP_Error(
1353 1353
 				"woocommerce_rest_{$this->post_type}_invalid_id",
1354
-				__( 'Invalid ID.', 'woocommerce' ),
1354
+				__('Invalid ID.', 'woocommerce'),
1355 1355
 				array(
1356 1356
 					'status' => 404,
1357 1357
 				)
1358 1358
 			);
1359 1359
 		}
1360 1360
 
1361
-		if ( 'variation' === $object->get_type() ) {
1361
+		if ('variation' === $object->get_type()) {
1362 1362
 			return new WP_Error(
1363 1363
 				"woocommerce_rest_invalid_{$this->post_type}_id",
1364
-				__( 'To manipulate product variations you should use the /products/&lt;product_id&gt;/variations/&lt;id&gt; endpoint.', 'woocommerce' ),
1364
+				__('To manipulate product variations you should use the /products/&lt;product_id&gt;/variations/&lt;id&gt; endpoint.', 'woocommerce'),
1365 1365
 				array(
1366 1366
 					'status' => 404,
1367 1367
 				)
1368 1368
 			);
1369 1369
 		}
1370 1370
 
1371
-		$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) );
1371
+		$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable(array($object, 'get_status'));
1372 1372
 
1373 1373
 		/**
1374 1374
 		 * Filter whether an object is trashable.
@@ -1378,51 +1378,51 @@  discard block
 block discarded – undo
1378 1378
 		 * @param boolean $supports_trash Whether the object type support trashing.
1379 1379
 		 * @param WC_Data $object         The object being considered for trashing support.
1380 1380
 		 */
1381
-		$supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object );
1381
+		$supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object);
1382 1382
 
1383
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
1383
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) {
1384 1384
 			return new WP_Error(
1385 1385
 				"woocommerce_rest_user_cannot_delete_{$this->post_type}",
1386 1386
 				/* translators: %s: post type */
1387
-				sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ),
1387
+				sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type),
1388 1388
 				array(
1389 1389
 					'status' => rest_authorization_required_code(),
1390 1390
 				)
1391 1391
 			);
1392 1392
 		}
1393 1393
 
1394
-		$request->set_param( 'context', 'edit' );
1395
-		$response = $this->prepare_object_for_response( $object, $request );
1394
+		$request->set_param('context', 'edit');
1395
+		$response = $this->prepare_object_for_response($object, $request);
1396 1396
 
1397 1397
 		// If we're forcing, then delete permanently.
1398
-		if ( $force ) {
1399
-			if ( $object->is_type( 'variable' ) ) {
1400
-				foreach ( $object->get_children() as $child_id ) {
1401
-					$child = wc_get_product( $child_id );
1402
-					if ( ! empty( $child ) ) {
1403
-						$child->delete( true );
1398
+		if ($force) {
1399
+			if ($object->is_type('variable')) {
1400
+				foreach ($object->get_children() as $child_id) {
1401
+					$child = wc_get_product($child_id);
1402
+					if ( ! empty($child)) {
1403
+						$child->delete(true);
1404 1404
 					}
1405 1405
 				}
1406 1406
 			} else {
1407 1407
 				// For other product types, if the product has children, remove the relationship.
1408
-				foreach ( $object->get_children() as $child_id ) {
1409
-					$child = wc_get_product( $child_id );
1410
-					if ( ! empty( $child ) ) {
1411
-						$child->set_parent_id( 0 );
1408
+				foreach ($object->get_children() as $child_id) {
1409
+					$child = wc_get_product($child_id);
1410
+					if ( ! empty($child)) {
1411
+						$child->set_parent_id(0);
1412 1412
 						$child->save();
1413 1413
 					}
1414 1414
 				}
1415 1415
 			}
1416 1416
 
1417
-			$object->delete( true );
1417
+			$object->delete(true);
1418 1418
 			$result = 0 === $object->get_id();
1419 1419
 		} else {
1420 1420
 			// If we don't support trashing for this type, error out.
1421
-			if ( ! $supports_trash ) {
1421
+			if ( ! $supports_trash) {
1422 1422
 				return new WP_Error(
1423 1423
 					'woocommerce_rest_trash_not_supported',
1424 1424
 					/* translators: %s: post type */
1425
-					sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ),
1425
+					sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type),
1426 1426
 					array(
1427 1427
 						'status' => 501,
1428 1428
 					)
@@ -1430,12 +1430,12 @@  discard block
 block discarded – undo
1430 1430
 			}
1431 1431
 
1432 1432
 			// Otherwise, only trash if we haven't already.
1433
-			if ( is_callable( array( $object, 'get_status' ) ) ) {
1434
-				if ( 'trash' === $object->get_status() ) {
1433
+			if (is_callable(array($object, 'get_status'))) {
1434
+				if ('trash' === $object->get_status()) {
1435 1435
 					return new WP_Error(
1436 1436
 						'woocommerce_rest_already_trashed',
1437 1437
 						/* translators: %s: post type */
1438
-						sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ),
1438
+						sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type),
1439 1439
 						array(
1440 1440
 							'status' => 410,
1441 1441
 						)
@@ -1447,11 +1447,11 @@  discard block
 block discarded – undo
1447 1447
 			}
1448 1448
 		}
1449 1449
 
1450
-		if ( ! $result ) {
1450
+		if ( ! $result) {
1451 1451
 			return new WP_Error(
1452 1452
 				'woocommerce_rest_cannot_delete',
1453 1453
 				/* translators: %s: post type */
1454
-				sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ),
1454
+				sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type),
1455 1455
 				array(
1456 1456
 					'status' => 500,
1457 1457
 				)
@@ -1459,8 +1459,8 @@  discard block
 block discarded – undo
1459 1459
 		}
1460 1460
 
1461 1461
 		// Delete parent product transients.
1462
-		if ( 0 !== $object->get_parent_id() ) {
1463
-			wc_delete_product_transients( $object->get_parent_id() );
1462
+		if (0 !== $object->get_parent_id()) {
1463
+			wc_delete_product_transients($object->get_parent_id());
1464 1464
 		}
1465 1465
 
1466 1466
 		/**
@@ -1470,7 +1470,7 @@  discard block
 block discarded – undo
1470 1470
 		 * @param WP_REST_Response $response The response data.
1471 1471
 		 * @param WP_REST_Request  $request  The request sent to the API.
1472 1472
 		 */
1473
-		do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request );
1473
+		do_action("woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request);
1474 1474
 
1475 1475
 		return $response;
1476 1476
 	}
@@ -1481,535 +1481,535 @@  discard block
 block discarded – undo
1481 1481
 	 * @return array
1482 1482
 	 */
1483 1483
 	public function get_item_schema() {
1484
-		$weight_unit    = get_option( 'woocommerce_weight_unit' );
1485
-		$dimension_unit = get_option( 'woocommerce_dimension_unit' );
1484
+		$weight_unit    = get_option('woocommerce_weight_unit');
1485
+		$dimension_unit = get_option('woocommerce_dimension_unit');
1486 1486
 		$schema         = array(
1487 1487
 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
1488 1488
 			'title'      => $this->post_type,
1489 1489
 			'type'       => 'object',
1490 1490
 			'properties' => array(
1491 1491
 				'id'                    => array(
1492
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
1492
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
1493 1493
 					'type'        => 'integer',
1494
-					'context'     => array( 'view', 'edit' ),
1494
+					'context'     => array('view', 'edit'),
1495 1495
 					'readonly'    => true,
1496 1496
 				),
1497 1497
 				'name'                  => array(
1498
-					'description' => __( 'Product name.', 'woocommerce' ),
1498
+					'description' => __('Product name.', 'woocommerce'),
1499 1499
 					'type'        => 'string',
1500
-					'context'     => array( 'view', 'edit' ),
1500
+					'context'     => array('view', 'edit'),
1501 1501
 				),
1502 1502
 				'slug'                  => array(
1503
-					'description' => __( 'Product slug.', 'woocommerce' ),
1503
+					'description' => __('Product slug.', 'woocommerce'),
1504 1504
 					'type'        => 'string',
1505
-					'context'     => array( 'view', 'edit' ),
1505
+					'context'     => array('view', 'edit'),
1506 1506
 				),
1507 1507
 				'permalink'             => array(
1508
-					'description' => __( 'Product URL.', 'woocommerce' ),
1508
+					'description' => __('Product URL.', 'woocommerce'),
1509 1509
 					'type'        => 'string',
1510 1510
 					'format'      => 'uri',
1511
-					'context'     => array( 'view', 'edit' ),
1511
+					'context'     => array('view', 'edit'),
1512 1512
 					'readonly'    => true,
1513 1513
 				),
1514 1514
 				'date_created'          => array(
1515
-					'description' => __( "The date the product was created, in the site's timezone.", 'woocommerce' ),
1515
+					'description' => __("The date the product was created, in the site's timezone.", 'woocommerce'),
1516 1516
 					'type'        => 'date-time',
1517
-					'context'     => array( 'view', 'edit' ),
1517
+					'context'     => array('view', 'edit'),
1518 1518
 					'readonly'    => true,
1519 1519
 				),
1520 1520
 				'date_created_gmt'      => array(
1521
-					'description' => __( 'The date the product was created, as GMT.', 'woocommerce' ),
1521
+					'description' => __('The date the product was created, as GMT.', 'woocommerce'),
1522 1522
 					'type'        => 'date-time',
1523
-					'context'     => array( 'view', 'edit' ),
1523
+					'context'     => array('view', 'edit'),
1524 1524
 					'readonly'    => true,
1525 1525
 				),
1526 1526
 				'date_modified'         => array(
1527
-					'description' => __( "The date the product was last modified, in the site's timezone.", 'woocommerce' ),
1527
+					'description' => __("The date the product was last modified, in the site's timezone.", 'woocommerce'),
1528 1528
 					'type'        => 'date-time',
1529
-					'context'     => array( 'view', 'edit' ),
1529
+					'context'     => array('view', 'edit'),
1530 1530
 					'readonly'    => true,
1531 1531
 				),
1532 1532
 				'date_modified_gmt'     => array(
1533
-					'description' => __( 'The date the product was last modified, as GMT.', 'woocommerce' ),
1533
+					'description' => __('The date the product was last modified, as GMT.', 'woocommerce'),
1534 1534
 					'type'        => 'date-time',
1535
-					'context'     => array( 'view', 'edit' ),
1535
+					'context'     => array('view', 'edit'),
1536 1536
 					'readonly'    => true,
1537 1537
 				),
1538 1538
 				'type'                  => array(
1539
-					'description' => __( 'Product type.', 'woocommerce' ),
1539
+					'description' => __('Product type.', 'woocommerce'),
1540 1540
 					'type'        => 'string',
1541 1541
 					'default'     => 'simple',
1542
-					'enum'        => array_keys( wc_get_product_types() ),
1543
-					'context'     => array( 'view', 'edit' ),
1542
+					'enum'        => array_keys(wc_get_product_types()),
1543
+					'context'     => array('view', 'edit'),
1544 1544
 				),
1545 1545
 				'status'                => array(
1546
-					'description' => __( 'Product status (post status).', 'woocommerce' ),
1546
+					'description' => __('Product status (post status).', 'woocommerce'),
1547 1547
 					'type'        => 'string',
1548 1548
 					'default'     => 'publish',
1549
-					'enum'        => array_merge( array_keys( get_post_statuses() ), array( 'future' ) ),
1550
-					'context'     => array( 'view', 'edit' ),
1549
+					'enum'        => array_merge(array_keys(get_post_statuses()), array('future')),
1550
+					'context'     => array('view', 'edit'),
1551 1551
 				),
1552 1552
 				'featured'              => array(
1553
-					'description' => __( 'Featured product.', 'woocommerce' ),
1553
+					'description' => __('Featured product.', 'woocommerce'),
1554 1554
 					'type'        => 'boolean',
1555 1555
 					'default'     => false,
1556
-					'context'     => array( 'view', 'edit' ),
1556
+					'context'     => array('view', 'edit'),
1557 1557
 				),
1558 1558
 				'catalog_visibility'    => array(
1559
-					'description' => __( 'Catalog visibility.', 'woocommerce' ),
1559
+					'description' => __('Catalog visibility.', 'woocommerce'),
1560 1560
 					'type'        => 'string',
1561 1561
 					'default'     => 'visible',
1562
-					'enum'        => array( 'visible', 'catalog', 'search', 'hidden' ),
1563
-					'context'     => array( 'view', 'edit' ),
1562
+					'enum'        => array('visible', 'catalog', 'search', 'hidden'),
1563
+					'context'     => array('view', 'edit'),
1564 1564
 				),
1565 1565
 				'description'           => array(
1566
-					'description' => __( 'Product description.', 'woocommerce' ),
1566
+					'description' => __('Product description.', 'woocommerce'),
1567 1567
 					'type'        => 'string',
1568
-					'context'     => array( 'view', 'edit' ),
1568
+					'context'     => array('view', 'edit'),
1569 1569
 				),
1570 1570
 				'short_description'     => array(
1571
-					'description' => __( 'Product short description.', 'woocommerce' ),
1571
+					'description' => __('Product short description.', 'woocommerce'),
1572 1572
 					'type'        => 'string',
1573
-					'context'     => array( 'view', 'edit' ),
1573
+					'context'     => array('view', 'edit'),
1574 1574
 				),
1575 1575
 				'sku'                   => array(
1576
-					'description' => __( 'Unique identifier.', 'woocommerce' ),
1576
+					'description' => __('Unique identifier.', 'woocommerce'),
1577 1577
 					'type'        => 'string',
1578
-					'context'     => array( 'view', 'edit' ),
1578
+					'context'     => array('view', 'edit'),
1579 1579
 				),
1580 1580
 				'price'                 => array(
1581
-					'description' => __( 'Current product price.', 'woocommerce' ),
1581
+					'description' => __('Current product price.', 'woocommerce'),
1582 1582
 					'type'        => 'string',
1583
-					'context'     => array( 'view', 'edit' ),
1583
+					'context'     => array('view', 'edit'),
1584 1584
 					'readonly'    => true,
1585 1585
 				),
1586 1586
 				'regular_price'         => array(
1587
-					'description' => __( 'Product regular price.', 'woocommerce' ),
1587
+					'description' => __('Product regular price.', 'woocommerce'),
1588 1588
 					'type'        => 'string',
1589
-					'context'     => array( 'view', 'edit' ),
1589
+					'context'     => array('view', 'edit'),
1590 1590
 				),
1591 1591
 				'sale_price'            => array(
1592
-					'description' => __( 'Product sale price.', 'woocommerce' ),
1592
+					'description' => __('Product sale price.', 'woocommerce'),
1593 1593
 					'type'        => 'string',
1594
-					'context'     => array( 'view', 'edit' ),
1594
+					'context'     => array('view', 'edit'),
1595 1595
 				),
1596 1596
 				'date_on_sale_from'     => array(
1597
-					'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ),
1597
+					'description' => __("Start date of sale price, in the site's timezone.", 'woocommerce'),
1598 1598
 					'type'        => 'date-time',
1599
-					'context'     => array( 'view', 'edit' ),
1599
+					'context'     => array('view', 'edit'),
1600 1600
 				),
1601 1601
 				'date_on_sale_from_gmt' => array(
1602
-					'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ),
1602
+					'description' => __('Start date of sale price, as GMT.', 'woocommerce'),
1603 1603
 					'type'        => 'date-time',
1604
-					'context'     => array( 'view', 'edit' ),
1604
+					'context'     => array('view', 'edit'),
1605 1605
 				),
1606 1606
 				'date_on_sale_to'       => array(
1607
-					'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
1607
+					'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'),
1608 1608
 					'type'        => 'date-time',
1609
-					'context'     => array( 'view', 'edit' ),
1609
+					'context'     => array('view', 'edit'),
1610 1610
 				),
1611 1611
 				'date_on_sale_to_gmt'   => array(
1612
-					'description' => __( 'End date of sale price, as GMT.', 'woocommerce' ),
1612
+					'description' => __('End date of sale price, as GMT.', 'woocommerce'),
1613 1613
 					'type'        => 'date-time',
1614
-					'context'     => array( 'view', 'edit' ),
1614
+					'context'     => array('view', 'edit'),
1615 1615
 				),
1616 1616
 				'price_html'            => array(
1617
-					'description' => __( 'Price formatted in HTML.', 'woocommerce' ),
1617
+					'description' => __('Price formatted in HTML.', 'woocommerce'),
1618 1618
 					'type'        => 'string',
1619
-					'context'     => array( 'view', 'edit' ),
1619
+					'context'     => array('view', 'edit'),
1620 1620
 					'readonly'    => true,
1621 1621
 				),
1622 1622
 				'on_sale'               => array(
1623
-					'description' => __( 'Shows if the product is on sale.', 'woocommerce' ),
1623
+					'description' => __('Shows if the product is on sale.', 'woocommerce'),
1624 1624
 					'type'        => 'boolean',
1625
-					'context'     => array( 'view', 'edit' ),
1625
+					'context'     => array('view', 'edit'),
1626 1626
 					'readonly'    => true,
1627 1627
 				),
1628 1628
 				'purchasable'           => array(
1629
-					'description' => __( 'Shows if the product can be bought.', 'woocommerce' ),
1629
+					'description' => __('Shows if the product can be bought.', 'woocommerce'),
1630 1630
 					'type'        => 'boolean',
1631
-					'context'     => array( 'view', 'edit' ),
1631
+					'context'     => array('view', 'edit'),
1632 1632
 					'readonly'    => true,
1633 1633
 				),
1634 1634
 				'total_sales'           => array(
1635
-					'description' => __( 'Amount of sales.', 'woocommerce' ),
1635
+					'description' => __('Amount of sales.', 'woocommerce'),
1636 1636
 					'type'        => 'integer',
1637
-					'context'     => array( 'view', 'edit' ),
1637
+					'context'     => array('view', 'edit'),
1638 1638
 					'readonly'    => true,
1639 1639
 				),
1640 1640
 				'virtual'               => array(
1641
-					'description' => __( 'If the product is virtual.', 'woocommerce' ),
1641
+					'description' => __('If the product is virtual.', 'woocommerce'),
1642 1642
 					'type'        => 'boolean',
1643 1643
 					'default'     => false,
1644
-					'context'     => array( 'view', 'edit' ),
1644
+					'context'     => array('view', 'edit'),
1645 1645
 				),
1646 1646
 				'downloadable'          => array(
1647
-					'description' => __( 'If the product is downloadable.', 'woocommerce' ),
1647
+					'description' => __('If the product is downloadable.', 'woocommerce'),
1648 1648
 					'type'        => 'boolean',
1649 1649
 					'default'     => false,
1650
-					'context'     => array( 'view', 'edit' ),
1650
+					'context'     => array('view', 'edit'),
1651 1651
 				),
1652 1652
 				'downloads'             => array(
1653
-					'description' => __( 'List of downloadable files.', 'woocommerce' ),
1653
+					'description' => __('List of downloadable files.', 'woocommerce'),
1654 1654
 					'type'        => 'array',
1655
-					'context'     => array( 'view', 'edit' ),
1655
+					'context'     => array('view', 'edit'),
1656 1656
 					'items'       => array(
1657 1657
 						'type'       => 'object',
1658 1658
 						'properties' => array(
1659 1659
 							'id'   => array(
1660
-								'description' => __( 'File ID.', 'woocommerce' ),
1660
+								'description' => __('File ID.', 'woocommerce'),
1661 1661
 								'type'        => 'string',
1662
-								'context'     => array( 'view', 'edit' ),
1662
+								'context'     => array('view', 'edit'),
1663 1663
 							),
1664 1664
 							'name' => array(
1665
-								'description' => __( 'File name.', 'woocommerce' ),
1665
+								'description' => __('File name.', 'woocommerce'),
1666 1666
 								'type'        => 'string',
1667
-								'context'     => array( 'view', 'edit' ),
1667
+								'context'     => array('view', 'edit'),
1668 1668
 							),
1669 1669
 							'file' => array(
1670
-								'description' => __( 'File URL.', 'woocommerce' ),
1670
+								'description' => __('File URL.', 'woocommerce'),
1671 1671
 								'type'        => 'string',
1672
-								'context'     => array( 'view', 'edit' ),
1672
+								'context'     => array('view', 'edit'),
1673 1673
 							),
1674 1674
 						),
1675 1675
 					),
1676 1676
 				),
1677 1677
 				'download_limit'        => array(
1678
-					'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ),
1678
+					'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'),
1679 1679
 					'type'        => 'integer',
1680 1680
 					'default'     => -1,
1681
-					'context'     => array( 'view', 'edit' ),
1681
+					'context'     => array('view', 'edit'),
1682 1682
 				),
1683 1683
 				'download_expiry'       => array(
1684
-					'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ),
1684
+					'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'),
1685 1685
 					'type'        => 'integer',
1686 1686
 					'default'     => -1,
1687
-					'context'     => array( 'view', 'edit' ),
1687
+					'context'     => array('view', 'edit'),
1688 1688
 				),
1689 1689
 				'external_url'          => array(
1690
-					'description' => __( 'Product external URL. Only for external products.', 'woocommerce' ),
1690
+					'description' => __('Product external URL. Only for external products.', 'woocommerce'),
1691 1691
 					'type'        => 'string',
1692 1692
 					'format'      => 'uri',
1693
-					'context'     => array( 'view', 'edit' ),
1693
+					'context'     => array('view', 'edit'),
1694 1694
 				),
1695 1695
 				'button_text'           => array(
1696
-					'description' => __( 'Product external button text. Only for external products.', 'woocommerce' ),
1696
+					'description' => __('Product external button text. Only for external products.', 'woocommerce'),
1697 1697
 					'type'        => 'string',
1698
-					'context'     => array( 'view', 'edit' ),
1698
+					'context'     => array('view', 'edit'),
1699 1699
 				),
1700 1700
 				'tax_status'            => array(
1701
-					'description' => __( 'Tax status.', 'woocommerce' ),
1701
+					'description' => __('Tax status.', 'woocommerce'),
1702 1702
 					'type'        => 'string',
1703 1703
 					'default'     => 'taxable',
1704
-					'enum'        => array( 'taxable', 'shipping', 'none' ),
1705
-					'context'     => array( 'view', 'edit' ),
1704
+					'enum'        => array('taxable', 'shipping', 'none'),
1705
+					'context'     => array('view', 'edit'),
1706 1706
 				),
1707 1707
 				'tax_class'             => array(
1708
-					'description' => __( 'Tax class.', 'woocommerce' ),
1708
+					'description' => __('Tax class.', 'woocommerce'),
1709 1709
 					'type'        => 'string',
1710
-					'context'     => array( 'view', 'edit' ),
1710
+					'context'     => array('view', 'edit'),
1711 1711
 				),
1712 1712
 				'manage_stock'          => array(
1713
-					'description' => __( 'Stock management at product level.', 'woocommerce' ),
1713
+					'description' => __('Stock management at product level.', 'woocommerce'),
1714 1714
 					'type'        => 'boolean',
1715 1715
 					'default'     => false,
1716
-					'context'     => array( 'view', 'edit' ),
1716
+					'context'     => array('view', 'edit'),
1717 1717
 				),
1718 1718
 				'stock_quantity'        => array(
1719
-					'description' => __( 'Stock quantity.', 'woocommerce' ),
1719
+					'description' => __('Stock quantity.', 'woocommerce'),
1720 1720
 					'type'        => 'integer',
1721
-					'context'     => array( 'view', 'edit' ),
1721
+					'context'     => array('view', 'edit'),
1722 1722
 				),
1723 1723
 				'in_stock'              => array(
1724
-					'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
1724
+					'description' => __('Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce'),
1725 1725
 					'type'        => 'boolean',
1726 1726
 					'default'     => true,
1727
-					'context'     => array( 'view', 'edit' ),
1727
+					'context'     => array('view', 'edit'),
1728 1728
 				),
1729 1729
 				'backorders'            => array(
1730
-					'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ),
1730
+					'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'),
1731 1731
 					'type'        => 'string',
1732 1732
 					'default'     => 'no',
1733
-					'enum'        => array( 'no', 'notify', 'yes' ),
1734
-					'context'     => array( 'view', 'edit' ),
1733
+					'enum'        => array('no', 'notify', 'yes'),
1734
+					'context'     => array('view', 'edit'),
1735 1735
 				),
1736 1736
 				'backorders_allowed'    => array(
1737
-					'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ),
1737
+					'description' => __('Shows if backorders are allowed.', 'woocommerce'),
1738 1738
 					'type'        => 'boolean',
1739
-					'context'     => array( 'view', 'edit' ),
1739
+					'context'     => array('view', 'edit'),
1740 1740
 					'readonly'    => true,
1741 1741
 				),
1742 1742
 				'backordered'           => array(
1743
-					'description' => __( 'Shows if the product is on backordered.', 'woocommerce' ),
1743
+					'description' => __('Shows if the product is on backordered.', 'woocommerce'),
1744 1744
 					'type'        => 'boolean',
1745
-					'context'     => array( 'view', 'edit' ),
1745
+					'context'     => array('view', 'edit'),
1746 1746
 					'readonly'    => true,
1747 1747
 				),
1748 1748
 				'sold_individually'     => array(
1749
-					'description' => __( 'Allow one item to be bought in a single order.', 'woocommerce' ),
1749
+					'description' => __('Allow one item to be bought in a single order.', 'woocommerce'),
1750 1750
 					'type'        => 'boolean',
1751 1751
 					'default'     => false,
1752
-					'context'     => array( 'view', 'edit' ),
1752
+					'context'     => array('view', 'edit'),
1753 1753
 				),
1754 1754
 				'weight'                => array(
1755 1755
 					/* translators: %s: weight unit */
1756
-					'description' => sprintf( __( 'Product weight (%s).', 'woocommerce' ), $weight_unit ),
1756
+					'description' => sprintf(__('Product weight (%s).', 'woocommerce'), $weight_unit),
1757 1757
 					'type'        => 'string',
1758
-					'context'     => array( 'view', 'edit' ),
1758
+					'context'     => array('view', 'edit'),
1759 1759
 				),
1760 1760
 				'dimensions'            => array(
1761
-					'description' => __( 'Product dimensions.', 'woocommerce' ),
1761
+					'description' => __('Product dimensions.', 'woocommerce'),
1762 1762
 					'type'        => 'object',
1763
-					'context'     => array( 'view', 'edit' ),
1763
+					'context'     => array('view', 'edit'),
1764 1764
 					'properties'  => array(
1765 1765
 						'length' => array(
1766 1766
 							/* translators: %s: dimension unit */
1767
-							'description' => sprintf( __( 'Product length (%s).', 'woocommerce' ), $dimension_unit ),
1767
+							'description' => sprintf(__('Product length (%s).', 'woocommerce'), $dimension_unit),
1768 1768
 							'type'        => 'string',
1769
-							'context'     => array( 'view', 'edit' ),
1769
+							'context'     => array('view', 'edit'),
1770 1770
 						),
1771 1771
 						'width'  => array(
1772 1772
 							/* translators: %s: dimension unit */
1773
-							'description' => sprintf( __( 'Product width (%s).', 'woocommerce' ), $dimension_unit ),
1773
+							'description' => sprintf(__('Product width (%s).', 'woocommerce'), $dimension_unit),
1774 1774
 							'type'        => 'string',
1775
-							'context'     => array( 'view', 'edit' ),
1775
+							'context'     => array('view', 'edit'),
1776 1776
 						),
1777 1777
 						'height' => array(
1778 1778
 							/* translators: %s: dimension unit */
1779
-							'description' => sprintf( __( 'Product height (%s).', 'woocommerce' ), $dimension_unit ),
1779
+							'description' => sprintf(__('Product height (%s).', 'woocommerce'), $dimension_unit),
1780 1780
 							'type'        => 'string',
1781
-							'context'     => array( 'view', 'edit' ),
1781
+							'context'     => array('view', 'edit'),
1782 1782
 						),
1783 1783
 					),
1784 1784
 				),
1785 1785
 				'shipping_required'     => array(
1786
-					'description' => __( 'Shows if the product need to be shipped.', 'woocommerce' ),
1786
+					'description' => __('Shows if the product need to be shipped.', 'woocommerce'),
1787 1787
 					'type'        => 'boolean',
1788
-					'context'     => array( 'view', 'edit' ),
1788
+					'context'     => array('view', 'edit'),
1789 1789
 					'readonly'    => true,
1790 1790
 				),
1791 1791
 				'shipping_taxable'      => array(
1792
-					'description' => __( 'Shows whether or not the product shipping is taxable.', 'woocommerce' ),
1792
+					'description' => __('Shows whether or not the product shipping is taxable.', 'woocommerce'),
1793 1793
 					'type'        => 'boolean',
1794
-					'context'     => array( 'view', 'edit' ),
1794
+					'context'     => array('view', 'edit'),
1795 1795
 					'readonly'    => true,
1796 1796
 				),
1797 1797
 				'shipping_class'        => array(
1798
-					'description' => __( 'Shipping class slug.', 'woocommerce' ),
1798
+					'description' => __('Shipping class slug.', 'woocommerce'),
1799 1799
 					'type'        => 'string',
1800
-					'context'     => array( 'view', 'edit' ),
1800
+					'context'     => array('view', 'edit'),
1801 1801
 				),
1802 1802
 				'shipping_class_id'     => array(
1803
-					'description' => __( 'Shipping class ID.', 'woocommerce' ),
1803
+					'description' => __('Shipping class ID.', 'woocommerce'),
1804 1804
 					'type'        => 'integer',
1805
-					'context'     => array( 'view', 'edit' ),
1805
+					'context'     => array('view', 'edit'),
1806 1806
 					'readonly'    => true,
1807 1807
 				),
1808 1808
 				'reviews_allowed'       => array(
1809
-					'description' => __( 'Allow reviews.', 'woocommerce' ),
1809
+					'description' => __('Allow reviews.', 'woocommerce'),
1810 1810
 					'type'        => 'boolean',
1811 1811
 					'default'     => true,
1812
-					'context'     => array( 'view', 'edit' ),
1812
+					'context'     => array('view', 'edit'),
1813 1813
 				),
1814 1814
 				'average_rating'        => array(
1815
-					'description' => __( 'Reviews average rating.', 'woocommerce' ),
1815
+					'description' => __('Reviews average rating.', 'woocommerce'),
1816 1816
 					'type'        => 'string',
1817
-					'context'     => array( 'view', 'edit' ),
1817
+					'context'     => array('view', 'edit'),
1818 1818
 					'readonly'    => true,
1819 1819
 				),
1820 1820
 				'rating_count'          => array(
1821
-					'description' => __( 'Amount of reviews that the product have.', 'woocommerce' ),
1821
+					'description' => __('Amount of reviews that the product have.', 'woocommerce'),
1822 1822
 					'type'        => 'integer',
1823
-					'context'     => array( 'view', 'edit' ),
1823
+					'context'     => array('view', 'edit'),
1824 1824
 					'readonly'    => true,
1825 1825
 				),
1826 1826
 				'related_ids'           => array(
1827
-					'description' => __( 'List of related products IDs.', 'woocommerce' ),
1827
+					'description' => __('List of related products IDs.', 'woocommerce'),
1828 1828
 					'type'        => 'array',
1829 1829
 					'items'       => array(
1830 1830
 						'type' => 'integer',
1831 1831
 					),
1832
-					'context'     => array( 'view', 'edit' ),
1832
+					'context'     => array('view', 'edit'),
1833 1833
 					'readonly'    => true,
1834 1834
 				),
1835 1835
 				'upsell_ids'            => array(
1836
-					'description' => __( 'List of up-sell products IDs.', 'woocommerce' ),
1836
+					'description' => __('List of up-sell products IDs.', 'woocommerce'),
1837 1837
 					'type'        => 'array',
1838 1838
 					'items'       => array(
1839 1839
 						'type' => 'integer',
1840 1840
 					),
1841
-					'context'     => array( 'view', 'edit' ),
1841
+					'context'     => array('view', 'edit'),
1842 1842
 				),
1843 1843
 				'cross_sell_ids'        => array(
1844
-					'description' => __( 'List of cross-sell products IDs.', 'woocommerce' ),
1844
+					'description' => __('List of cross-sell products IDs.', 'woocommerce'),
1845 1845
 					'type'        => 'array',
1846 1846
 					'items'       => array(
1847 1847
 						'type' => 'integer',
1848 1848
 					),
1849
-					'context'     => array( 'view', 'edit' ),
1849
+					'context'     => array('view', 'edit'),
1850 1850
 				),
1851 1851
 				'parent_id'             => array(
1852
-					'description' => __( 'Product parent ID.', 'woocommerce' ),
1852
+					'description' => __('Product parent ID.', 'woocommerce'),
1853 1853
 					'type'        => 'integer',
1854
-					'context'     => array( 'view', 'edit' ),
1854
+					'context'     => array('view', 'edit'),
1855 1855
 				),
1856 1856
 				'purchase_note'         => array(
1857
-					'description' => __( 'Optional note to send the customer after purchase.', 'woocommerce' ),
1857
+					'description' => __('Optional note to send the customer after purchase.', 'woocommerce'),
1858 1858
 					'type'        => 'string',
1859
-					'context'     => array( 'view', 'edit' ),
1859
+					'context'     => array('view', 'edit'),
1860 1860
 				),
1861 1861
 				'categories'            => array(
1862
-					'description' => __( 'List of categories.', 'woocommerce' ),
1862
+					'description' => __('List of categories.', 'woocommerce'),
1863 1863
 					'type'        => 'array',
1864
-					'context'     => array( 'view', 'edit' ),
1864
+					'context'     => array('view', 'edit'),
1865 1865
 					'items'       => array(
1866 1866
 						'type'       => 'object',
1867 1867
 						'properties' => array(
1868 1868
 							'id'   => array(
1869
-								'description' => __( 'Category ID.', 'woocommerce' ),
1869
+								'description' => __('Category ID.', 'woocommerce'),
1870 1870
 								'type'        => 'integer',
1871
-								'context'     => array( 'view', 'edit' ),
1871
+								'context'     => array('view', 'edit'),
1872 1872
 							),
1873 1873
 							'name' => array(
1874
-								'description' => __( 'Category name.', 'woocommerce' ),
1874
+								'description' => __('Category name.', 'woocommerce'),
1875 1875
 								'type'        => 'string',
1876
-								'context'     => array( 'view', 'edit' ),
1876
+								'context'     => array('view', 'edit'),
1877 1877
 								'readonly'    => true,
1878 1878
 							),
1879 1879
 							'slug' => array(
1880
-								'description' => __( 'Category slug.', 'woocommerce' ),
1880
+								'description' => __('Category slug.', 'woocommerce'),
1881 1881
 								'type'        => 'string',
1882
-								'context'     => array( 'view', 'edit' ),
1882
+								'context'     => array('view', 'edit'),
1883 1883
 								'readonly'    => true,
1884 1884
 							),
1885 1885
 						),
1886 1886
 					),
1887 1887
 				),
1888 1888
 				'tags'                  => array(
1889
-					'description' => __( 'List of tags.', 'woocommerce' ),
1889
+					'description' => __('List of tags.', 'woocommerce'),
1890 1890
 					'type'        => 'array',
1891
-					'context'     => array( 'view', 'edit' ),
1891
+					'context'     => array('view', 'edit'),
1892 1892
 					'items'       => array(
1893 1893
 						'type'       => 'object',
1894 1894
 						'properties' => array(
1895 1895
 							'id'   => array(
1896
-								'description' => __( 'Tag ID.', 'woocommerce' ),
1896
+								'description' => __('Tag ID.', 'woocommerce'),
1897 1897
 								'type'        => 'integer',
1898
-								'context'     => array( 'view', 'edit' ),
1898
+								'context'     => array('view', 'edit'),
1899 1899
 							),
1900 1900
 							'name' => array(
1901
-								'description' => __( 'Tag name.', 'woocommerce' ),
1901
+								'description' => __('Tag name.', 'woocommerce'),
1902 1902
 								'type'        => 'string',
1903
-								'context'     => array( 'view', 'edit' ),
1903
+								'context'     => array('view', 'edit'),
1904 1904
 								'readonly'    => true,
1905 1905
 							),
1906 1906
 							'slug' => array(
1907
-								'description' => __( 'Tag slug.', 'woocommerce' ),
1907
+								'description' => __('Tag slug.', 'woocommerce'),
1908 1908
 								'type'        => 'string',
1909
-								'context'     => array( 'view', 'edit' ),
1909
+								'context'     => array('view', 'edit'),
1910 1910
 								'readonly'    => true,
1911 1911
 							),
1912 1912
 						),
1913 1913
 					),
1914 1914
 				),
1915 1915
 				'images'                => array(
1916
-					'description' => __( 'List of images.', 'woocommerce' ),
1916
+					'description' => __('List of images.', 'woocommerce'),
1917 1917
 					'type'        => 'array',
1918
-					'context'     => array( 'view', 'edit' ),
1918
+					'context'     => array('view', 'edit'),
1919 1919
 					'items'       => array(
1920 1920
 						'type'       => 'object',
1921 1921
 						'properties' => array(
1922 1922
 							'id'                => array(
1923
-								'description' => __( 'Image ID.', 'woocommerce' ),
1923
+								'description' => __('Image ID.', 'woocommerce'),
1924 1924
 								'type'        => 'integer',
1925
-								'context'     => array( 'view', 'edit' ),
1925
+								'context'     => array('view', 'edit'),
1926 1926
 							),
1927 1927
 							'date_created'      => array(
1928
-								'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ),
1928
+								'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'),
1929 1929
 								'type'        => 'date-time',
1930
-								'context'     => array( 'view', 'edit' ),
1930
+								'context'     => array('view', 'edit'),
1931 1931
 								'readonly'    => true,
1932 1932
 							),
1933 1933
 							'date_created_gmt'  => array(
1934
-								'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ),
1934
+								'description' => __('The date the image was created, as GMT.', 'woocommerce'),
1935 1935
 								'type'        => 'date-time',
1936
-								'context'     => array( 'view', 'edit' ),
1936
+								'context'     => array('view', 'edit'),
1937 1937
 								'readonly'    => true,
1938 1938
 							),
1939 1939
 							'date_modified'     => array(
1940
-								'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ),
1940
+								'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'),
1941 1941
 								'type'        => 'date-time',
1942
-								'context'     => array( 'view', 'edit' ),
1942
+								'context'     => array('view', 'edit'),
1943 1943
 								'readonly'    => true,
1944 1944
 							),
1945 1945
 							'date_modified_gmt' => array(
1946
-								'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ),
1946
+								'description' => __('The date the image was last modified, as GMT.', 'woocommerce'),
1947 1947
 								'type'        => 'date-time',
1948
-								'context'     => array( 'view', 'edit' ),
1948
+								'context'     => array('view', 'edit'),
1949 1949
 								'readonly'    => true,
1950 1950
 							),
1951 1951
 							'src'               => array(
1952
-								'description' => __( 'Image URL.', 'woocommerce' ),
1952
+								'description' => __('Image URL.', 'woocommerce'),
1953 1953
 								'type'        => 'string',
1954 1954
 								'format'      => 'uri',
1955
-								'context'     => array( 'view', 'edit' ),
1955
+								'context'     => array('view', 'edit'),
1956 1956
 							),
1957 1957
 							'name'              => array(
1958
-								'description' => __( 'Image name.', 'woocommerce' ),
1958
+								'description' => __('Image name.', 'woocommerce'),
1959 1959
 								'type'        => 'string',
1960
-								'context'     => array( 'view', 'edit' ),
1960
+								'context'     => array('view', 'edit'),
1961 1961
 							),
1962 1962
 							'alt'               => array(
1963
-								'description' => __( 'Image alternative text.', 'woocommerce' ),
1963
+								'description' => __('Image alternative text.', 'woocommerce'),
1964 1964
 								'type'        => 'string',
1965
-								'context'     => array( 'view', 'edit' ),
1965
+								'context'     => array('view', 'edit'),
1966 1966
 							),
1967 1967
 							'position'          => array(
1968
-								'description' => __( 'Image position. 0 means that the image is featured.', 'woocommerce' ),
1968
+								'description' => __('Image position. 0 means that the image is featured.', 'woocommerce'),
1969 1969
 								'type'        => 'integer',
1970
-								'context'     => array( 'view', 'edit' ),
1970
+								'context'     => array('view', 'edit'),
1971 1971
 							),
1972 1972
 						),
1973 1973
 					),
1974 1974
 				),
1975 1975
 				'attributes'            => array(
1976
-					'description' => __( 'List of attributes.', 'woocommerce' ),
1976
+					'description' => __('List of attributes.', 'woocommerce'),
1977 1977
 					'type'        => 'array',
1978
-					'context'     => array( 'view', 'edit' ),
1978
+					'context'     => array('view', 'edit'),
1979 1979
 					'items'       => array(
1980 1980
 						'type'       => 'object',
1981 1981
 						'properties' => array(
1982 1982
 							'id'        => array(
1983
-								'description' => __( 'Attribute ID.', 'woocommerce' ),
1983
+								'description' => __('Attribute ID.', 'woocommerce'),
1984 1984
 								'type'        => 'integer',
1985
-								'context'     => array( 'view', 'edit' ),
1985
+								'context'     => array('view', 'edit'),
1986 1986
 							),
1987 1987
 							'name'      => array(
1988
-								'description' => __( 'Attribute name.', 'woocommerce' ),
1988
+								'description' => __('Attribute name.', 'woocommerce'),
1989 1989
 								'type'        => 'string',
1990
-								'context'     => array( 'view', 'edit' ),
1990
+								'context'     => array('view', 'edit'),
1991 1991
 							),
1992 1992
 							'position'  => array(
1993
-								'description' => __( 'Attribute position.', 'woocommerce' ),
1993
+								'description' => __('Attribute position.', 'woocommerce'),
1994 1994
 								'type'        => 'integer',
1995
-								'context'     => array( 'view', 'edit' ),
1995
+								'context'     => array('view', 'edit'),
1996 1996
 							),
1997 1997
 							'visible'   => array(
1998
-								'description' => __( "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", 'woocommerce' ),
1998
+								'description' => __("Define if the attribute is visible on the \"Additional information\" tab in the product's page.", 'woocommerce'),
1999 1999
 								'type'        => 'boolean',
2000 2000
 								'default'     => false,
2001
-								'context'     => array( 'view', 'edit' ),
2001
+								'context'     => array('view', 'edit'),
2002 2002
 							),
2003 2003
 							'variation' => array(
2004
-								'description' => __( 'Define if the attribute can be used as variation.', 'woocommerce' ),
2004
+								'description' => __('Define if the attribute can be used as variation.', 'woocommerce'),
2005 2005
 								'type'        => 'boolean',
2006 2006
 								'default'     => false,
2007
-								'context'     => array( 'view', 'edit' ),
2007
+								'context'     => array('view', 'edit'),
2008 2008
 							),
2009 2009
 							'options'   => array(
2010
-								'description' => __( 'List of available term names of the attribute.', 'woocommerce' ),
2010
+								'description' => __('List of available term names of the attribute.', 'woocommerce'),
2011 2011
 								'type'        => 'array',
2012
-								'context'     => array( 'view', 'edit' ),
2012
+								'context'     => array('view', 'edit'),
2013 2013
 								'items'       => array(
2014 2014
 									'type' => 'string',
2015 2015
 								),
@@ -2018,74 +2018,74 @@  discard block
 block discarded – undo
2018 2018
 					),
2019 2019
 				),
2020 2020
 				'default_attributes'    => array(
2021
-					'description' => __( 'Defaults variation attributes.', 'woocommerce' ),
2021
+					'description' => __('Defaults variation attributes.', 'woocommerce'),
2022 2022
 					'type'        => 'array',
2023
-					'context'     => array( 'view', 'edit' ),
2023
+					'context'     => array('view', 'edit'),
2024 2024
 					'items'       => array(
2025 2025
 						'type'       => 'object',
2026 2026
 						'properties' => array(
2027 2027
 							'id'     => array(
2028
-								'description' => __( 'Attribute ID.', 'woocommerce' ),
2028
+								'description' => __('Attribute ID.', 'woocommerce'),
2029 2029
 								'type'        => 'integer',
2030
-								'context'     => array( 'view', 'edit' ),
2030
+								'context'     => array('view', 'edit'),
2031 2031
 							),
2032 2032
 							'name'   => array(
2033
-								'description' => __( 'Attribute name.', 'woocommerce' ),
2033
+								'description' => __('Attribute name.', 'woocommerce'),
2034 2034
 								'type'        => 'string',
2035
-								'context'     => array( 'view', 'edit' ),
2035
+								'context'     => array('view', 'edit'),
2036 2036
 							),
2037 2037
 							'option' => array(
2038
-								'description' => __( 'Selected attribute term name.', 'woocommerce' ),
2038
+								'description' => __('Selected attribute term name.', 'woocommerce'),
2039 2039
 								'type'        => 'string',
2040
-								'context'     => array( 'view', 'edit' ),
2040
+								'context'     => array('view', 'edit'),
2041 2041
 							),
2042 2042
 						),
2043 2043
 					),
2044 2044
 				),
2045 2045
 				'variations'            => array(
2046
-					'description' => __( 'List of variations IDs.', 'woocommerce' ),
2046
+					'description' => __('List of variations IDs.', 'woocommerce'),
2047 2047
 					'type'        => 'array',
2048
-					'context'     => array( 'view', 'edit' ),
2048
+					'context'     => array('view', 'edit'),
2049 2049
 					'items'       => array(
2050 2050
 						'type' => 'integer',
2051 2051
 					),
2052 2052
 					'readonly'    => true,
2053 2053
 				),
2054 2054
 				'grouped_products'      => array(
2055
-					'description' => __( 'List of grouped products ID.', 'woocommerce' ),
2055
+					'description' => __('List of grouped products ID.', 'woocommerce'),
2056 2056
 					'type'        => 'array',
2057 2057
 					'items'       => array(
2058 2058
 						'type' => 'integer',
2059 2059
 					),
2060
-					'context'     => array( 'view', 'edit' ),
2060
+					'context'     => array('view', 'edit'),
2061 2061
 				),
2062 2062
 				'menu_order'            => array(
2063
-					'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ),
2063
+					'description' => __('Menu order, used to custom sort products.', 'woocommerce'),
2064 2064
 					'type'        => 'integer',
2065
-					'context'     => array( 'view', 'edit' ),
2065
+					'context'     => array('view', 'edit'),
2066 2066
 				),
2067 2067
 				'meta_data'             => array(
2068
-					'description' => __( 'Meta data.', 'woocommerce' ),
2068
+					'description' => __('Meta data.', 'woocommerce'),
2069 2069
 					'type'        => 'array',
2070
-					'context'     => array( 'view', 'edit' ),
2070
+					'context'     => array('view', 'edit'),
2071 2071
 					'items'       => array(
2072 2072
 						'type'       => 'object',
2073 2073
 						'properties' => array(
2074 2074
 							'id'    => array(
2075
-								'description' => __( 'Meta ID.', 'woocommerce' ),
2075
+								'description' => __('Meta ID.', 'woocommerce'),
2076 2076
 								'type'        => 'integer',
2077
-								'context'     => array( 'view', 'edit' ),
2077
+								'context'     => array('view', 'edit'),
2078 2078
 								'readonly'    => true,
2079 2079
 							),
2080 2080
 							'key'   => array(
2081
-								'description' => __( 'Meta key.', 'woocommerce' ),
2081
+								'description' => __('Meta key.', 'woocommerce'),
2082 2082
 								'type'        => 'string',
2083
-								'context'     => array( 'view', 'edit' ),
2083
+								'context'     => array('view', 'edit'),
2084 2084
 							),
2085 2085
 							'value' => array(
2086
-								'description' => __( 'Meta value.', 'woocommerce' ),
2086
+								'description' => __('Meta value.', 'woocommerce'),
2087 2087
 								'type'        => 'mixed',
2088
-								'context'     => array( 'view', 'edit' ),
2088
+								'context'     => array('view', 'edit'),
2089 2089
 							),
2090 2090
 						),
2091 2091
 					),
@@ -2093,7 +2093,7 @@  discard block
 block discarded – undo
2093 2093
 			),
2094 2094
 		);
2095 2095
 
2096
-		return $this->add_additional_fields_schema( $schema );
2096
+		return $this->add_additional_fields_schema($schema);
2097 2097
 	}
2098 2098
 
2099 2099
 	/**
@@ -2104,99 +2104,99 @@  discard block
 block discarded – undo
2104 2104
 	public function get_collection_params() {
2105 2105
 		$params = parent::get_collection_params();
2106 2106
 
2107
-		$params['slug']           = array(
2108
-			'description'       => __( 'Limit result set to products with a specific slug.', 'woocommerce' ),
2107
+		$params['slug'] = array(
2108
+			'description'       => __('Limit result set to products with a specific slug.', 'woocommerce'),
2109 2109
 			'type'              => 'string',
2110 2110
 			'validate_callback' => 'rest_validate_request_arg',
2111 2111
 		);
2112
-		$params['status']         = array(
2112
+		$params['status'] = array(
2113 2113
 			'default'           => 'any',
2114
-			'description'       => __( 'Limit result set to products assigned a specific status.', 'woocommerce' ),
2114
+			'description'       => __('Limit result set to products assigned a specific status.', 'woocommerce'),
2115 2115
 			'type'              => 'string',
2116
-			'enum'              => array_merge( array( 'any', 'future' ), array_keys( get_post_statuses() ) ),
2116
+			'enum'              => array_merge(array('any', 'future'), array_keys(get_post_statuses())),
2117 2117
 			'sanitize_callback' => 'sanitize_key',
2118 2118
 			'validate_callback' => 'rest_validate_request_arg',
2119 2119
 		);
2120
-		$params['type']           = array(
2121
-			'description'       => __( 'Limit result set to products assigned a specific type.', 'woocommerce' ),
2120
+		$params['type'] = array(
2121
+			'description'       => __('Limit result set to products assigned a specific type.', 'woocommerce'),
2122 2122
 			'type'              => 'string',
2123
-			'enum'              => array_keys( wc_get_product_types() ),
2123
+			'enum'              => array_keys(wc_get_product_types()),
2124 2124
 			'sanitize_callback' => 'sanitize_key',
2125 2125
 			'validate_callback' => 'rest_validate_request_arg',
2126 2126
 		);
2127
-		$params['sku']            = array(
2128
-			'description'       => __( 'Limit result set to products with specific SKU(s). Use commas to separate.', 'woocommerce' ),
2127
+		$params['sku'] = array(
2128
+			'description'       => __('Limit result set to products with specific SKU(s). Use commas to separate.', 'woocommerce'),
2129 2129
 			'type'              => 'string',
2130 2130
 			'sanitize_callback' => 'sanitize_text_field',
2131 2131
 			'validate_callback' => 'rest_validate_request_arg',
2132 2132
 		);
2133
-		$params['featured']       = array(
2134
-			'description'       => __( 'Limit result set to featured products.', 'woocommerce' ),
2133
+		$params['featured'] = array(
2134
+			'description'       => __('Limit result set to featured products.', 'woocommerce'),
2135 2135
 			'type'              => 'boolean',
2136 2136
 			'sanitize_callback' => 'wc_string_to_bool',
2137 2137
 			'validate_callback' => 'rest_validate_request_arg',
2138 2138
 		);
2139
-		$params['category']       = array(
2140
-			'description'       => __( 'Limit result set to products assigned a specific category ID.', 'woocommerce' ),
2139
+		$params['category'] = array(
2140
+			'description'       => __('Limit result set to products assigned a specific category ID.', 'woocommerce'),
2141 2141
 			'type'              => 'string',
2142 2142
 			'sanitize_callback' => 'wp_parse_id_list',
2143 2143
 			'validate_callback' => 'rest_validate_request_arg',
2144 2144
 		);
2145
-		$params['tag']            = array(
2146
-			'description'       => __( 'Limit result set to products assigned a specific tag ID.', 'woocommerce' ),
2145
+		$params['tag'] = array(
2146
+			'description'       => __('Limit result set to products assigned a specific tag ID.', 'woocommerce'),
2147 2147
 			'type'              => 'string',
2148 2148
 			'sanitize_callback' => 'wp_parse_id_list',
2149 2149
 			'validate_callback' => 'rest_validate_request_arg',
2150 2150
 		);
2151 2151
 		$params['shipping_class'] = array(
2152
-			'description'       => __( 'Limit result set to products assigned a specific shipping class ID.', 'woocommerce' ),
2152
+			'description'       => __('Limit result set to products assigned a specific shipping class ID.', 'woocommerce'),
2153 2153
 			'type'              => 'string',
2154 2154
 			'sanitize_callback' => 'wp_parse_id_list',
2155 2155
 			'validate_callback' => 'rest_validate_request_arg',
2156 2156
 		);
2157
-		$params['attribute']      = array(
2158
-			'description'       => __( 'Limit result set to products with a specific attribute. Use the taxonomy name/attribute slug.', 'woocommerce' ),
2157
+		$params['attribute'] = array(
2158
+			'description'       => __('Limit result set to products with a specific attribute. Use the taxonomy name/attribute slug.', 'woocommerce'),
2159 2159
 			'type'              => 'string',
2160 2160
 			'sanitize_callback' => 'sanitize_text_field',
2161 2161
 			'validate_callback' => 'rest_validate_request_arg',
2162 2162
 		);
2163 2163
 		$params['attribute_term'] = array(
2164
-			'description'       => __( 'Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'woocommerce' ),
2164
+			'description'       => __('Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'woocommerce'),
2165 2165
 			'type'              => 'string',
2166 2166
 			'sanitize_callback' => 'wp_parse_id_list',
2167 2167
 			'validate_callback' => 'rest_validate_request_arg',
2168 2168
 		);
2169 2169
 
2170
-		if ( wc_tax_enabled() ) {
2170
+		if (wc_tax_enabled()) {
2171 2171
 			$params['tax_class'] = array(
2172
-				'description'       => __( 'Limit result set to products with a specific tax class.', 'woocommerce' ),
2172
+				'description'       => __('Limit result set to products with a specific tax class.', 'woocommerce'),
2173 2173
 				'type'              => 'string',
2174
-				'enum'              => array_merge( array( 'standard' ), WC_Tax::get_tax_class_slugs() ),
2174
+				'enum'              => array_merge(array('standard'), WC_Tax::get_tax_class_slugs()),
2175 2175
 				'sanitize_callback' => 'sanitize_text_field',
2176 2176
 				'validate_callback' => 'rest_validate_request_arg',
2177 2177
 			);
2178 2178
 		}
2179 2179
 
2180
-		$params['in_stock']  = array(
2181
-			'description'       => __( 'Limit result set to products in stock or out of stock.', 'woocommerce' ),
2180
+		$params['in_stock'] = array(
2181
+			'description'       => __('Limit result set to products in stock or out of stock.', 'woocommerce'),
2182 2182
 			'type'              => 'boolean',
2183 2183
 			'sanitize_callback' => 'wc_string_to_bool',
2184 2184
 			'validate_callback' => 'rest_validate_request_arg',
2185 2185
 		);
2186
-		$params['on_sale']   = array(
2187
-			'description'       => __( 'Limit result set to products on sale.', 'woocommerce' ),
2186
+		$params['on_sale'] = array(
2187
+			'description'       => __('Limit result set to products on sale.', 'woocommerce'),
2188 2188
 			'type'              => 'boolean',
2189 2189
 			'sanitize_callback' => 'wc_string_to_bool',
2190 2190
 			'validate_callback' => 'rest_validate_request_arg',
2191 2191
 		);
2192 2192
 		$params['min_price'] = array(
2193
-			'description'       => __( 'Limit result set to products based on a minimum price.', 'woocommerce' ),
2193
+			'description'       => __('Limit result set to products based on a minimum price.', 'woocommerce'),
2194 2194
 			'type'              => 'string',
2195 2195
 			'sanitize_callback' => 'sanitize_text_field',
2196 2196
 			'validate_callback' => 'rest_validate_request_arg',
2197 2197
 		);
2198 2198
 		$params['max_price'] = array(
2199
-			'description'       => __( 'Limit result set to products based on a maximum price.', 'woocommerce' ),
2199
+			'description'       => __('Limit result set to products based on a maximum price.', 'woocommerce'),
2200 2200
 			'type'              => 'string',
2201 2201
 			'sanitize_callback' => 'sanitize_text_field',
2202 2202
 			'validate_callback' => 'rest_validate_request_arg',
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-shipping-methods-v2-controller.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   3.0.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * Shipping methods controller class.
@@ -40,30 +40,30 @@  discard block
 block discarded – undo
40 40
 			$this->namespace, '/' . $this->rest_base, array(
41 41
 				array(
42 42
 					'methods'             => WP_REST_Server::READABLE,
43
-					'callback'            => array( $this, 'get_items' ),
44
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
43
+					'callback'            => array($this, 'get_items'),
44
+					'permission_callback' => array($this, 'get_items_permissions_check'),
45 45
 					'args'                => $this->get_collection_params(),
46 46
 				),
47
-				'schema' => array( $this, 'get_public_item_schema' ),
47
+				'schema' => array($this, 'get_public_item_schema'),
48 48
 			)
49 49
 		);
50 50
 		register_rest_route(
51 51
 			$this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
52 52
 				'args'   => array(
53 53
 					'id' => array(
54
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
54
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
55 55
 						'type'        => 'string',
56 56
 					),
57 57
 				),
58 58
 				array(
59 59
 					'methods'             => WP_REST_Server::READABLE,
60
-					'callback'            => array( $this, 'get_item' ),
61
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
60
+					'callback'            => array($this, 'get_item'),
61
+					'permission_callback' => array($this, 'get_item_permissions_check'),
62 62
 					'args'                => array(
63
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
63
+						'context' => $this->get_context_param(array('default' => 'view')),
64 64
 					),
65 65
 				),
66
-				'schema' => array( $this, 'get_public_item_schema' ),
66
+				'schema' => array($this, 'get_public_item_schema'),
67 67
 			)
68 68
 		);
69 69
 	}
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
 	 * @param  WP_REST_Request $request Full details about the request.
75 75
 	 * @return WP_Error|boolean
76 76
 	 */
77
-	public function get_items_permissions_check( $request ) {
78
-		if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) {
79
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
77
+	public function get_items_permissions_check($request) {
78
+		if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) {
79
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
80 80
 		}
81 81
 		return true;
82 82
 	}
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 	 * @param  WP_REST_Request $request Full details about the request.
88 88
 	 * @return WP_Error|boolean
89 89
 	 */
90
-	public function get_item_permissions_check( $request ) {
91
-		if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) {
92
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
90
+	public function get_item_permissions_check($request) {
91
+		if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) {
92
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
93 93
 		}
94 94
 		return true;
95 95
 	}
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
 	 * @param WP_REST_Request $request Full details about the request.
101 101
 	 * @return WP_Error|WP_REST_Response
102 102
 	 */
103
-	public function get_items( $request ) {
103
+	public function get_items($request) {
104 104
 		$wc_shipping = WC_Shipping::instance();
105 105
 		$response    = array();
106
-		foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) {
107
-			$method     = $this->prepare_item_for_response( $shipping_method, $request );
108
-			$method     = $this->prepare_response_for_collection( $method );
106
+		foreach ($wc_shipping->get_shipping_methods() as $id => $shipping_method) {
107
+			$method     = $this->prepare_item_for_response($shipping_method, $request);
108
+			$method     = $this->prepare_response_for_collection($method);
109 109
 			$response[] = $method;
110 110
 		}
111
-		return rest_ensure_response( $response );
111
+		return rest_ensure_response($response);
112 112
 	}
113 113
 
114 114
 	/**
@@ -117,17 +117,17 @@  discard block
 block discarded – undo
117 117
 	 * @param WP_REST_Request $request Request data.
118 118
 	 * @return WP_REST_Response|WP_Error
119 119
 	 */
120
-	public function get_item( $request ) {
120
+	public function get_item($request) {
121 121
 		$wc_shipping = WC_Shipping::instance();
122 122
 		$methods     = $wc_shipping->get_shipping_methods();
123
-		if ( empty( $methods[ $request['id'] ] ) ) {
124
-			return new WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
123
+		if (empty($methods[$request['id']])) {
124
+			return new WP_Error('woocommerce_rest_shipping_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
125 125
 		}
126 126
 
127
-		$method   = $methods[ $request['id'] ];
128
-		$response = $this->prepare_item_for_response( $method, $request );
127
+		$method   = $methods[$request['id']];
128
+		$response = $this->prepare_item_for_response($method, $request);
129 129
 
130
-		return rest_ensure_response( $response );
130
+		return rest_ensure_response($response);
131 131
 	}
132 132
 
133 133
 	/**
@@ -137,21 +137,21 @@  discard block
 block discarded – undo
137 137
 	 * @param  WP_REST_Request    $request  Request object.
138 138
 	 * @return WP_REST_Response   $response Response data.
139 139
 	 */
140
-	public function prepare_item_for_response( $method, $request ) {
140
+	public function prepare_item_for_response($method, $request) {
141 141
 		$data = array(
142 142
 			'id'          => $method->id,
143 143
 			'title'       => $method->method_title,
144 144
 			'description' => $method->method_description,
145 145
 		);
146 146
 
147
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
148
-		$data    = $this->add_additional_fields_to_object( $data, $request );
149
-		$data    = $this->filter_response_by_context( $data, $context );
147
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
148
+		$data    = $this->add_additional_fields_to_object($data, $request);
149
+		$data    = $this->filter_response_by_context($data, $context);
150 150
 
151 151
 		// Wrap the data in a response object.
152
-		$response = rest_ensure_response( $data );
152
+		$response = rest_ensure_response($data);
153 153
 
154
-		$response->add_links( $this->prepare_links( $method, $request ) );
154
+		$response->add_links($this->prepare_links($method, $request));
155 155
 
156 156
 		/**
157 157
 		 * Filter shipping methods object returned from the REST API.
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		 * @param WC_Shipping_Method $method   Shipping method object used to create response.
161 161
 		 * @param WP_REST_Request    $request  Request object.
162 162
 		 */
163
-		return apply_filters( 'woocommerce_rest_prepare_shipping_method', $response, $method, $request );
163
+		return apply_filters('woocommerce_rest_prepare_shipping_method', $response, $method, $request);
164 164
 	}
165 165
 
166 166
 	/**
@@ -170,13 +170,13 @@  discard block
 block discarded – undo
170 170
 	 * @param WP_REST_Request    $request Request object.
171 171
 	 * @return array
172 172
 	 */
173
-	protected function prepare_links( $method, $request ) {
173
+	protected function prepare_links($method, $request) {
174 174
 		$links = array(
175 175
 			'self'       => array(
176
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $method->id ) ),
176
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $method->id)),
177 177
 			),
178 178
 			'collection' => array(
179
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
179
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
180 180
 			),
181 181
 		);
182 182
 
@@ -195,27 +195,27 @@  discard block
 block discarded – undo
195 195
 			'type'       => 'object',
196 196
 			'properties' => array(
197 197
 				'id'          => array(
198
-					'description' => __( 'Method ID.', 'woocommerce' ),
198
+					'description' => __('Method ID.', 'woocommerce'),
199 199
 					'type'        => 'string',
200
-					'context'     => array( 'view' ),
200
+					'context'     => array('view'),
201 201
 					'readonly'    => true,
202 202
 				),
203 203
 				'title'       => array(
204
-					'description' => __( 'Shipping method title.', 'woocommerce' ),
204
+					'description' => __('Shipping method title.', 'woocommerce'),
205 205
 					'type'        => 'string',
206
-					'context'     => array( 'view' ),
206
+					'context'     => array('view'),
207 207
 					'readonly'    => true,
208 208
 				),
209 209
 				'description' => array(
210
-					'description' => __( 'Shipping method description.', 'woocommerce' ),
210
+					'description' => __('Shipping method description.', 'woocommerce'),
211 211
 					'type'        => 'string',
212
-					'context'     => array( 'view' ),
212
+					'context'     => array('view'),
213 213
 					'readonly'    => true,
214 214
 				),
215 215
 			),
216 216
 		);
217 217
 
218
-		return $this->add_additional_fields_schema( $schema );
218
+		return $this->add_additional_fields_schema($schema);
219 219
 	}
220 220
 
221 221
 	/**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 */
226 226
 	public function get_collection_params() {
227 227
 		return array(
228
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
228
+			'context' => $this->get_context_param(array('default' => 'view')),
229 229
 		);
230 230
 	}
231 231
 }
Please login to merge, or discard this patch.
Version2/class-wc-rest-shipping-zone-locations-v2-controller.php 1 patch
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   3.0.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Shipping Zone Locations class.
@@ -26,22 +26,22 @@  discard block
 block discarded – undo
26 26
 			$this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)/locations', array(
27 27
 				'args'   => array(
28 28
 					'id' => array(
29
-						'description' => __( 'Unique ID for the resource.', 'woocommerce' ),
29
+						'description' => __('Unique ID for the resource.', 'woocommerce'),
30 30
 						'type'        => 'integer',
31 31
 					),
32 32
 				),
33 33
 				array(
34 34
 					'methods'             => WP_REST_Server::READABLE,
35
-					'callback'            => array( $this, 'get_items' ),
36
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
35
+					'callback'            => array($this, 'get_items'),
36
+					'permission_callback' => array($this, 'get_items_permissions_check'),
37 37
 				),
38 38
 				array(
39 39
 					'methods'             => WP_REST_Server::EDITABLE,
40
-					'callback'            => array( $this, 'update_items' ),
41
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
42
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
40
+					'callback'            => array($this, 'update_items'),
41
+					'permission_callback' => array($this, 'update_items_permissions_check'),
42
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
43 43
 				),
44
-				'schema' => array( $this, 'get_public_item_schema' ),
44
+				'schema' => array($this, 'get_public_item_schema'),
45 45
 			)
46 46
 		);
47 47
 	}
@@ -52,23 +52,23 @@  discard block
 block discarded – undo
52 52
 	 * @param WP_REST_Request $request Request data.
53 53
 	 * @return WP_REST_Response|WP_Error
54 54
 	 */
55
-	public function get_items( $request ) {
56
-		$zone = $this->get_zone( (int) $request['id'] );
55
+	public function get_items($request) {
56
+		$zone = $this->get_zone((int) $request['id']);
57 57
 
58
-		if ( is_wp_error( $zone ) ) {
58
+		if (is_wp_error($zone)) {
59 59
 			return $zone;
60 60
 		}
61 61
 
62 62
 		$locations = $zone->get_zone_locations();
63 63
 		$data      = array();
64 64
 
65
-		foreach ( $locations as $location_obj ) {
66
-			$location = $this->prepare_item_for_response( $location_obj, $request );
67
-			$location = $this->prepare_response_for_collection( $location );
65
+		foreach ($locations as $location_obj) {
66
+			$location = $this->prepare_item_for_response($location_obj, $request);
67
+			$location = $this->prepare_response_for_collection($location);
68 68
 			$data[]   = $location;
69 69
 		}
70 70
 
71
-		return rest_ensure_response( $data );
71
+		return rest_ensure_response($data);
72 72
 	}
73 73
 
74 74
 	/**
@@ -77,41 +77,41 @@  discard block
 block discarded – undo
77 77
 	 * @param WP_REST_Request $request Request data.
78 78
 	 * @return WP_REST_Response|WP_Error
79 79
 	 */
80
-	public function update_items( $request ) {
81
-		$zone = $this->get_zone( (int) $request['id'] );
80
+	public function update_items($request) {
81
+		$zone = $this->get_zone((int) $request['id']);
82 82
 
83
-		if ( is_wp_error( $zone ) ) {
83
+		if (is_wp_error($zone)) {
84 84
 			return $zone;
85 85
 		}
86 86
 
87
-		if ( 0 === $zone->get_id() ) {
88
-			return new WP_Error( 'woocommerce_rest_shipping_zone_locations_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) );
87
+		if (0 === $zone->get_id()) {
88
+			return new WP_Error('woocommerce_rest_shipping_zone_locations_invalid_zone', __('The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce'), array('status' => 403));
89 89
 		}
90 90
 
91 91
 		$raw_locations = $request->get_json_params();
92 92
 		$locations     = array();
93 93
 
94
-		foreach ( (array) $raw_locations as $raw_location ) {
95
-			if ( empty( $raw_location['code'] ) ) {
94
+		foreach ((array) $raw_locations as $raw_location) {
95
+			if (empty($raw_location['code'])) {
96 96
 				continue;
97 97
 			}
98 98
 
99
-			$type = ! empty( $raw_location['type'] ) ? sanitize_text_field( $raw_location['type'] ) : 'country';
99
+			$type = ! empty($raw_location['type']) ? sanitize_text_field($raw_location['type']) : 'country';
100 100
 
101
-			if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) {
101
+			if ( ! in_array($type, array('postcode', 'state', 'country', 'continent'), true)) {
102 102
 				continue;
103 103
 			}
104 104
 
105 105
 			$locations[] = array(
106
-				'code' => sanitize_text_field( $raw_location['code'] ),
107
-				'type' => sanitize_text_field( $type ),
106
+				'code' => sanitize_text_field($raw_location['code']),
107
+				'type' => sanitize_text_field($type),
108 108
 			);
109 109
 		}
110 110
 
111
-		$zone->set_locations( $locations );
111
+		$zone->set_locations($locations);
112 112
 		$zone->save();
113 113
 
114
-		return $this->get_items( $request );
114
+		return $this->get_items($request);
115 115
 	}
116 116
 
117 117
 	/**
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 	 * @param WP_REST_Request $request Request object.
122 122
 	 * @return WP_REST_Response $response
123 123
 	 */
124
-	public function prepare_item_for_response( $item, $request ) {
125
-		$context = empty( $request['context'] ) ? 'view' : $request['context'];
126
-		$data    = $this->add_additional_fields_to_object( $item, $request );
127
-		$data    = $this->filter_response_by_context( $data, $context );
124
+	public function prepare_item_for_response($item, $request) {
125
+		$context = empty($request['context']) ? 'view' : $request['context'];
126
+		$data    = $this->add_additional_fields_to_object($item, $request);
127
+		$data    = $this->filter_response_by_context($data, $context);
128 128
 
129 129
 		// Wrap the data in a response object.
130
-		$response = rest_ensure_response( $data );
130
+		$response = rest_ensure_response($data);
131 131
 
132
-		$response->add_links( $this->prepare_links( (int) $request['id'] ) );
132
+		$response->add_links($this->prepare_links((int) $request['id']));
133 133
 
134 134
 		return $response;
135 135
 	}
@@ -140,14 +140,14 @@  discard block
 block discarded – undo
140 140
 	 * @param int $zone_id Given Shipping Zone ID.
141 141
 	 * @return array Links for the given Shipping Zone Location.
142 142
 	 */
143
-	protected function prepare_links( $zone_id ) {
143
+	protected function prepare_links($zone_id) {
144 144
 		$base  = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id;
145 145
 		$links = array(
146 146
 			'collection' => array(
147
-				'href' => rest_url( $base . '/locations' ),
147
+				'href' => rest_url($base . '/locations'),
148 148
 			),
149 149
 			'describes'  => array(
150
-				'href' => rest_url( $base ),
150
+				'href' => rest_url($base),
151 151
 			),
152 152
 		);
153 153
 
@@ -166,12 +166,12 @@  discard block
 block discarded – undo
166 166
 			'type'       => 'object',
167 167
 			'properties' => array(
168 168
 				'code' => array(
169
-					'description' => __( 'Shipping zone location code.', 'woocommerce' ),
169
+					'description' => __('Shipping zone location code.', 'woocommerce'),
170 170
 					'type'        => 'string',
171
-					'context'     => array( 'view', 'edit' ),
171
+					'context'     => array('view', 'edit'),
172 172
 				),
173 173
 				'type' => array(
174
-					'description' => __( 'Shipping zone location type.', 'woocommerce' ),
174
+					'description' => __('Shipping zone location type.', 'woocommerce'),
175 175
 					'type'        => 'string',
176 176
 					'default'     => 'country',
177 177
 					'enum'        => array(
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
 						'country',
181 181
 						'continent',
182 182
 					),
183
-					'context'     => array( 'view', 'edit' ),
183
+					'context'     => array('view', 'edit'),
184 184
 				),
185 185
 			),
186 186
 		);
187 187
 
188
-		return $this->add_additional_fields_schema( $schema );
188
+		return $this->add_additional_fields_schema($schema);
189 189
 	}
190 190
 }
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-product-categories-v2-controller.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Product Categories controller class.
@@ -32,12 +32,12 @@  discard block
 block discarded – undo
32 32
 	 * @param WP_REST_Request $request Request instance.
33 33
 	 * @return WP_REST_Response
34 34
 	 */
35
-	public function prepare_item_for_response( $item, $request ) {
35
+	public function prepare_item_for_response($item, $request) {
36 36
 		// Get category display type.
37
-		$display_type = get_term_meta( $item->term_id, 'display_type', true );
37
+		$display_type = get_term_meta($item->term_id, 'display_type', true);
38 38
 
39 39
 		// Get category order.
40
-		$menu_order = get_term_meta( $item->term_id, 'order', true );
40
+		$menu_order = get_term_meta($item->term_id, 'order', true);
41 41
 
42 42
 		$data = array(
43 43
 			'id'          => (int) $item->term_id,
@@ -52,29 +52,29 @@  discard block
 block discarded – undo
52 52
 		);
53 53
 
54 54
 		// Get category image.
55
-		$image_id = get_term_meta( $item->term_id, 'thumbnail_id', true );
56
-		if ( $image_id ) {
57
-			$attachment = get_post( $image_id );
55
+		$image_id = get_term_meta($item->term_id, 'thumbnail_id', true);
56
+		if ($image_id) {
57
+			$attachment = get_post($image_id);
58 58
 
59 59
 			$data['image'] = array(
60 60
 				'id'                => (int) $image_id,
61
-				'date_created'      => wc_rest_prepare_date_response( $attachment->post_date ),
62
-				'date_created_gmt'  => wc_rest_prepare_date_response( $attachment->post_date_gmt ),
63
-				'date_modified'     => wc_rest_prepare_date_response( $attachment->post_modified ),
64
-				'date_modified_gmt' => wc_rest_prepare_date_response( $attachment->post_modified_gmt ),
65
-				'src'               => wp_get_attachment_url( $image_id ),
66
-				'title'             => get_the_title( $attachment ),
67
-				'alt'               => get_post_meta( $image_id, '_wp_attachment_image_alt', true ),
61
+				'date_created'      => wc_rest_prepare_date_response($attachment->post_date),
62
+				'date_created_gmt'  => wc_rest_prepare_date_response($attachment->post_date_gmt),
63
+				'date_modified'     => wc_rest_prepare_date_response($attachment->post_modified),
64
+				'date_modified_gmt' => wc_rest_prepare_date_response($attachment->post_modified_gmt),
65
+				'src'               => wp_get_attachment_url($image_id),
66
+				'title'             => get_the_title($attachment),
67
+				'alt'               => get_post_meta($image_id, '_wp_attachment_image_alt', true),
68 68
 			);
69 69
 		}
70 70
 
71
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
72
-		$data    = $this->add_additional_fields_to_object( $data, $request );
73
-		$data    = $this->filter_response_by_context( $data, $context );
71
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
72
+		$data    = $this->add_additional_fields_to_object($data, $request);
73
+		$data    = $this->filter_response_by_context($data, $context);
74 74
 
75
-		$response = rest_ensure_response( $data );
75
+		$response = rest_ensure_response($data);
76 76
 
77
-		$response->add_links( $this->prepare_links( $item, $request ) );
77
+		$response->add_links($this->prepare_links($item, $request));
78 78
 
79 79
 		/**
80 80
 		 * Filter a term item returned from the API.
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 		 * @param object            $item      The original term object.
86 86
 		 * @param WP_REST_Request   $request   Request used to generate the response.
87 87
 		 */
88
-		return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request );
88
+		return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request);
89 89
 	}
90 90
 
91 91
 	/**
@@ -100,113 +100,113 @@  discard block
 block discarded – undo
100 100
 			'type'       => 'object',
101 101
 			'properties' => array(
102 102
 				'id'          => array(
103
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
103
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
104 104
 					'type'        => 'integer',
105
-					'context'     => array( 'view', 'edit' ),
105
+					'context'     => array('view', 'edit'),
106 106
 					'readonly'    => true,
107 107
 				),
108 108
 				'name'        => array(
109
-					'description' => __( 'Category name.', 'woocommerce' ),
109
+					'description' => __('Category name.', 'woocommerce'),
110 110
 					'type'        => 'string',
111
-					'context'     => array( 'view', 'edit' ),
111
+					'context'     => array('view', 'edit'),
112 112
 					'arg_options' => array(
113 113
 						'sanitize_callback' => 'sanitize_text_field',
114 114
 					),
115 115
 				),
116 116
 				'slug'        => array(
117
-					'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ),
117
+					'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'),
118 118
 					'type'        => 'string',
119
-					'context'     => array( 'view', 'edit' ),
119
+					'context'     => array('view', 'edit'),
120 120
 					'arg_options' => array(
121 121
 						'sanitize_callback' => 'sanitize_title',
122 122
 					),
123 123
 				),
124 124
 				'parent'      => array(
125
-					'description' => __( 'The ID for the parent of the resource.', 'woocommerce' ),
125
+					'description' => __('The ID for the parent of the resource.', 'woocommerce'),
126 126
 					'type'        => 'integer',
127
-					'context'     => array( 'view', 'edit' ),
127
+					'context'     => array('view', 'edit'),
128 128
 				),
129 129
 				'description' => array(
130
-					'description' => __( 'HTML description of the resource.', 'woocommerce' ),
130
+					'description' => __('HTML description of the resource.', 'woocommerce'),
131 131
 					'type'        => 'string',
132
-					'context'     => array( 'view', 'edit' ),
132
+					'context'     => array('view', 'edit'),
133 133
 					'arg_options' => array(
134 134
 						'sanitize_callback' => 'wp_filter_post_kses',
135 135
 					),
136 136
 				),
137 137
 				'display'     => array(
138
-					'description' => __( 'Category archive display type.', 'woocommerce' ),
138
+					'description' => __('Category archive display type.', 'woocommerce'),
139 139
 					'type'        => 'string',
140 140
 					'default'     => 'default',
141
-					'enum'        => array( 'default', 'products', 'subcategories', 'both' ),
142
-					'context'     => array( 'view', 'edit' ),
141
+					'enum'        => array('default', 'products', 'subcategories', 'both'),
142
+					'context'     => array('view', 'edit'),
143 143
 				),
144 144
 				'image'       => array(
145
-					'description' => __( 'Image data.', 'woocommerce' ),
145
+					'description' => __('Image data.', 'woocommerce'),
146 146
 					'type'        => 'object',
147
-					'context'     => array( 'view', 'edit' ),
147
+					'context'     => array('view', 'edit'),
148 148
 					'properties'  => array(
149 149
 						'id'                => array(
150
-							'description' => __( 'Image ID.', 'woocommerce' ),
150
+							'description' => __('Image ID.', 'woocommerce'),
151 151
 							'type'        => 'integer',
152
-							'context'     => array( 'view', 'edit' ),
152
+							'context'     => array('view', 'edit'),
153 153
 						),
154 154
 						'date_created'      => array(
155
-							'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ),
155
+							'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'),
156 156
 							'type'        => 'date-time',
157
-							'context'     => array( 'view', 'edit' ),
157
+							'context'     => array('view', 'edit'),
158 158
 							'readonly'    => true,
159 159
 						),
160 160
 						'date_created_gmt'  => array(
161
-							'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ),
161
+							'description' => __('The date the image was created, as GMT.', 'woocommerce'),
162 162
 							'type'        => 'date-time',
163
-							'context'     => array( 'view', 'edit' ),
163
+							'context'     => array('view', 'edit'),
164 164
 							'readonly'    => true,
165 165
 						),
166 166
 						'date_modified'     => array(
167
-							'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ),
167
+							'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'),
168 168
 							'type'        => 'date-time',
169
-							'context'     => array( 'view', 'edit' ),
169
+							'context'     => array('view', 'edit'),
170 170
 							'readonly'    => true,
171 171
 						),
172 172
 						'date_modified_gmt' => array(
173
-							'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ),
173
+							'description' => __('The date the image was last modified, as GMT.', 'woocommerce'),
174 174
 							'type'        => 'date-time',
175
-							'context'     => array( 'view', 'edit' ),
175
+							'context'     => array('view', 'edit'),
176 176
 							'readonly'    => true,
177 177
 						),
178 178
 						'src'               => array(
179
-							'description' => __( 'Image URL.', 'woocommerce' ),
179
+							'description' => __('Image URL.', 'woocommerce'),
180 180
 							'type'        => 'string',
181 181
 							'format'      => 'uri',
182
-							'context'     => array( 'view', 'edit' ),
182
+							'context'     => array('view', 'edit'),
183 183
 						),
184 184
 						'title'             => array(
185
-							'description' => __( 'Image name.', 'woocommerce' ),
185
+							'description' => __('Image name.', 'woocommerce'),
186 186
 							'type'        => 'string',
187
-							'context'     => array( 'view', 'edit' ),
187
+							'context'     => array('view', 'edit'),
188 188
 						),
189 189
 						'alt'               => array(
190
-							'description' => __( 'Image alternative text.', 'woocommerce' ),
190
+							'description' => __('Image alternative text.', 'woocommerce'),
191 191
 							'type'        => 'string',
192
-							'context'     => array( 'view', 'edit' ),
192
+							'context'     => array('view', 'edit'),
193 193
 						),
194 194
 					),
195 195
 				),
196 196
 				'menu_order'  => array(
197
-					'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ),
197
+					'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'),
198 198
 					'type'        => 'integer',
199
-					'context'     => array( 'view', 'edit' ),
199
+					'context'     => array('view', 'edit'),
200 200
 				),
201 201
 				'count'       => array(
202
-					'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
202
+					'description' => __('Number of published products for the resource.', 'woocommerce'),
203 203
 					'type'        => 'integer',
204
-					'context'     => array( 'view', 'edit' ),
204
+					'context'     => array('view', 'edit'),
205 205
 					'readonly'    => true,
206 206
 				),
207 207
 			),
208 208
 		);
209 209
 
210
-		return $this->add_additional_fields_schema( $schema );
210
+		return $this->add_additional_fields_schema($schema);
211 211
 	}
212 212
 }
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-report-top-sellers-v2-controller.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Report Top Sellers controller class.
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-orders-v2-controller.php 1 patch
Spacing   +482 added lines, -482 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since    2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Orders controller class.
@@ -63,17 +63,17 @@  discard block
 block discarded – undo
63 63
 			array(
64 64
 				array(
65 65
 					'methods'             => WP_REST_Server::READABLE,
66
-					'callback'            => array( $this, 'get_items' ),
67
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
66
+					'callback'            => array($this, 'get_items'),
67
+					'permission_callback' => array($this, 'get_items_permissions_check'),
68 68
 					'args'                => $this->get_collection_params(),
69 69
 				),
70 70
 				array(
71 71
 					'methods'             => WP_REST_Server::CREATABLE,
72
-					'callback'            => array( $this, 'create_item' ),
73
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
74
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
72
+					'callback'            => array($this, 'create_item'),
73
+					'permission_callback' => array($this, 'create_item_permissions_check'),
74
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
75 75
 				),
76
-				'schema' => array( $this, 'get_public_item_schema' ),
76
+				'schema' => array($this, 'get_public_item_schema'),
77 77
 			)
78 78
 		);
79 79
 
@@ -83,37 +83,37 @@  discard block
 block discarded – undo
83 83
 			array(
84 84
 				'args'   => array(
85 85
 					'id' => array(
86
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
86
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
87 87
 						'type'        => 'integer',
88 88
 					),
89 89
 				),
90 90
 				array(
91 91
 					'methods'             => WP_REST_Server::READABLE,
92
-					'callback'            => array( $this, 'get_item' ),
93
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
92
+					'callback'            => array($this, 'get_item'),
93
+					'permission_callback' => array($this, 'get_item_permissions_check'),
94 94
 					'args'                => array(
95
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
95
+						'context' => $this->get_context_param(array('default' => 'view')),
96 96
 					),
97 97
 				),
98 98
 				array(
99 99
 					'methods'             => WP_REST_Server::EDITABLE,
100
-					'callback'            => array( $this, 'update_item' ),
101
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
102
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
100
+					'callback'            => array($this, 'update_item'),
101
+					'permission_callback' => array($this, 'update_item_permissions_check'),
102
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
103 103
 				),
104 104
 				array(
105 105
 					'methods'             => WP_REST_Server::DELETABLE,
106
-					'callback'            => array( $this, 'delete_item' ),
107
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
106
+					'callback'            => array($this, 'delete_item'),
107
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
108 108
 					'args'                => array(
109 109
 						'force' => array(
110 110
 							'default'     => false,
111 111
 							'type'        => 'boolean',
112
-							'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
112
+							'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'),
113 113
 						),
114 114
 					),
115 115
 				),
116
-				'schema' => array( $this, 'get_public_item_schema' ),
116
+				'schema' => array($this, 'get_public_item_schema'),
117 117
 			)
118 118
 		);
119 119
 
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
 			array(
124 124
 				array(
125 125
 					'methods'             => WP_REST_Server::EDITABLE,
126
-					'callback'            => array( $this, 'batch_items' ),
127
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
128
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
126
+					'callback'            => array($this, 'batch_items'),
127
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
128
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
129 129
 				),
130
-				'schema' => array( $this, 'get_public_batch_schema' ),
130
+				'schema' => array($this, 'get_public_batch_schema'),
131 131
 			)
132 132
 		);
133 133
 	}
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
 	 * @param  int $id Object ID.
140 140
 	 * @return WC_Data|bool
141 141
 	 */
142
-	protected function get_object( $id ) {
143
-		$order = wc_get_order( $id );
142
+	protected function get_object($id) {
143
+		$order = wc_get_order($id);
144 144
 		// In case id is a refund's id (or it's not an order at all), don't expose it via /orders/ path.
145
-		if ( ! $order || 'shop_order_refund' === $order->get_type() ) {
145
+		if ( ! $order || 'shop_order_refund' === $order->get_type()) {
146 146
 			return false;
147 147
 		}
148 148
 
@@ -155,47 +155,47 @@  discard block
 block discarded – undo
155 155
 	 * @param WC_Order_item $item Order item data.
156 156
 	 * @return array
157 157
 	 */
158
-	protected function get_order_item_data( $item ) {
158
+	protected function get_order_item_data($item) {
159 159
 		$data           = $item->get_data();
160
-		$format_decimal = array( 'subtotal', 'subtotal_tax', 'total', 'total_tax', 'tax_total', 'shipping_tax_total' );
160
+		$format_decimal = array('subtotal', 'subtotal_tax', 'total', 'total_tax', 'tax_total', 'shipping_tax_total');
161 161
 
162 162
 		// Format decimal values.
163
-		foreach ( $format_decimal as $key ) {
164
-			if ( isset( $data[ $key ] ) ) {
165
-				$data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] );
163
+		foreach ($format_decimal as $key) {
164
+			if (isset($data[$key])) {
165
+				$data[$key] = wc_format_decimal($data[$key], $this->request['dp']);
166 166
 			}
167 167
 		}
168 168
 
169 169
 		// Add SKU and PRICE to products.
170
-		if ( is_callable( array( $item, 'get_product' ) ) ) {
170
+		if (is_callable(array($item, 'get_product'))) {
171 171
 			$data['sku']   = $item->get_product() ? $item->get_product()->get_sku() : null;
172 172
 			$data['price'] = $item->get_quantity() ? $item->get_total() / $item->get_quantity() : 0;
173 173
 		}
174 174
 
175 175
 		// Format taxes.
176
-		if ( ! empty( $data['taxes']['total'] ) ) {
176
+		if ( ! empty($data['taxes']['total'])) {
177 177
 			$taxes = array();
178 178
 
179
-			foreach ( $data['taxes']['total'] as $tax_rate_id => $tax ) {
179
+			foreach ($data['taxes']['total'] as $tax_rate_id => $tax) {
180 180
 				$taxes[] = array(
181 181
 					'id'       => $tax_rate_id,
182 182
 					'total'    => $tax,
183
-					'subtotal' => isset( $data['taxes']['subtotal'][ $tax_rate_id ] ) ? $data['taxes']['subtotal'][ $tax_rate_id ] : '',
183
+					'subtotal' => isset($data['taxes']['subtotal'][$tax_rate_id]) ? $data['taxes']['subtotal'][$tax_rate_id] : '',
184 184
 				);
185 185
 			}
186 186
 			$data['taxes'] = $taxes;
187
-		} elseif ( isset( $data['taxes'] ) ) {
187
+		} elseif (isset($data['taxes'])) {
188 188
 			$data['taxes'] = array();
189 189
 		}
190 190
 
191 191
 		// Remove names for coupons, taxes and shipping.
192
-		if ( isset( $data['code'] ) || isset( $data['rate_code'] ) || isset( $data['method_title'] ) ) {
193
-			unset( $data['name'] );
192
+		if (isset($data['code']) || isset($data['rate_code']) || isset($data['method_title'])) {
193
+			unset($data['name']);
194 194
 		}
195 195
 
196 196
 		// Remove props we don't want to expose.
197
-		unset( $data['order_id'] );
198
-		unset( $data['type'] );
197
+		unset($data['order_id']);
198
+		unset($data['type']);
199 199
 
200 200
 		return $data;
201 201
 	}
@@ -207,39 +207,39 @@  discard block
 block discarded – undo
207 207
 	 * @param  WC_Data $object WC_Data instance.
208 208
 	 * @return array
209 209
 	 */
210
-	protected function get_formatted_item_data( $object ) {
210
+	protected function get_formatted_item_data($object) {
211 211
 		$data              = $object->get_data();
212
-		$format_decimal    = array( 'discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax' );
213
-		$format_date       = array( 'date_created', 'date_modified', 'date_completed', 'date_paid' );
214
-		$format_line_items = array( 'line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines' );
212
+		$format_decimal    = array('discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax');
213
+		$format_date       = array('date_created', 'date_modified', 'date_completed', 'date_paid');
214
+		$format_line_items = array('line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines');
215 215
 
216 216
 		// Format decimal values.
217
-		foreach ( $format_decimal as $key ) {
218
-			$data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] );
217
+		foreach ($format_decimal as $key) {
218
+			$data[$key] = wc_format_decimal($data[$key], $this->request['dp']);
219 219
 		}
220 220
 
221 221
 		// Format date values.
222
-		foreach ( $format_date as $key ) {
223
-			$datetime              = $data[ $key ];
224
-			$data[ $key ]          = wc_rest_prepare_date_response( $datetime, false );
225
-			$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
222
+		foreach ($format_date as $key) {
223
+			$datetime              = $data[$key];
224
+			$data[$key]          = wc_rest_prepare_date_response($datetime, false);
225
+			$data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime);
226 226
 		}
227 227
 
228 228
 		// Format the order status.
229
-		$data['status'] = 'wc-' === substr( $data['status'], 0, 3 ) ? substr( $data['status'], 3 ) : $data['status'];
229
+		$data['status'] = 'wc-' === substr($data['status'], 0, 3) ? substr($data['status'], 3) : $data['status'];
230 230
 
231 231
 		// Format line items.
232
-		foreach ( $format_line_items as $key ) {
233
-			$data[ $key ] = array_values( array_map( array( $this, 'get_order_item_data' ), $data[ $key ] ) );
232
+		foreach ($format_line_items as $key) {
233
+			$data[$key] = array_values(array_map(array($this, 'get_order_item_data'), $data[$key]));
234 234
 		}
235 235
 
236 236
 		// Refunds.
237 237
 		$data['refunds'] = array();
238
-		foreach ( $object->get_refunds() as $refund ) {
238
+		foreach ($object->get_refunds() as $refund) {
239 239
 			$data['refunds'][] = array(
240 240
 				'id'     => $refund->get_id(),
241 241
 				'reason' => $refund->get_reason() ? $refund->get_reason() : '',
242
-				'total'  => '-' . wc_format_decimal( $refund->get_amount(), $this->request['dp'] ),
242
+				'total'  => '-' . wc_format_decimal($refund->get_amount(), $this->request['dp']),
243 243
 			);
244 244
 		}
245 245
 
@@ -296,15 +296,15 @@  discard block
 block discarded – undo
296 296
 	 * @param  WP_REST_Request $request Request object.
297 297
 	 * @return WP_REST_Response
298 298
 	 */
299
-	public function prepare_object_for_response( $object, $request ) {
299
+	public function prepare_object_for_response($object, $request) {
300 300
 		$this->request       = $request;
301
-		$this->request['dp'] = is_null( $this->request['dp'] ) ? wc_get_price_decimals() : absint( $this->request['dp'] );
302
-		$data                = $this->get_formatted_item_data( $object );
303
-		$context             = ! empty( $request['context'] ) ? $request['context'] : 'view';
304
-		$data                = $this->add_additional_fields_to_object( $data, $request );
305
-		$data                = $this->filter_response_by_context( $data, $context );
306
-		$response            = rest_ensure_response( $data );
307
-		$response->add_links( $this->prepare_links( $object, $request ) );
301
+		$this->request['dp'] = is_null($this->request['dp']) ? wc_get_price_decimals() : absint($this->request['dp']);
302
+		$data                = $this->get_formatted_item_data($object);
303
+		$context             = ! empty($request['context']) ? $request['context'] : 'view';
304
+		$data                = $this->add_additional_fields_to_object($data, $request);
305
+		$data                = $this->filter_response_by_context($data, $context);
306
+		$response            = rest_ensure_response($data);
307
+		$response->add_links($this->prepare_links($object, $request));
308 308
 
309 309
 		/**
310 310
 		 * Filter the data for a response.
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		 * @param WC_Data          $object   Object data.
317 317
 		 * @param WP_REST_Request  $request  Request object.
318 318
 		 */
319
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
319
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request);
320 320
 	}
321 321
 
322 322
 	/**
@@ -326,25 +326,25 @@  discard block
 block discarded – undo
326 326
 	 * @param WP_REST_Request $request Request object.
327 327
 	 * @return array                   Links for the given post.
328 328
 	 */
329
-	protected function prepare_links( $object, $request ) {
329
+	protected function prepare_links($object, $request) {
330 330
 		$links = array(
331 331
 			'self'       => array(
332
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ),
332
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())),
333 333
 			),
334 334
 			'collection' => array(
335
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
335
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
336 336
 			),
337 337
 		);
338 338
 
339
-		if ( 0 !== (int) $object->get_customer_id() ) {
339
+		if (0 !== (int) $object->get_customer_id()) {
340 340
 			$links['customer'] = array(
341
-				'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $object->get_customer_id() ) ),
341
+				'href' => rest_url(sprintf('/%s/customers/%d', $this->namespace, $object->get_customer_id())),
342 342
 			);
343 343
 		}
344 344
 
345
-		if ( 0 !== (int) $object->get_parent_id() ) {
345
+		if (0 !== (int) $object->get_parent_id()) {
346 346
 			$links['up'] = array(
347
-				'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $object->get_parent_id() ) ),
347
+				'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $object->get_parent_id())),
348 348
 			);
349 349
 		}
350 350
 
@@ -358,22 +358,22 @@  discard block
 block discarded – undo
358 358
 	 * @param  WP_REST_Request $request Full details about the request.
359 359
 	 * @return array
360 360
 	 */
361
-	protected function prepare_objects_query( $request ) {
361
+	protected function prepare_objects_query($request) {
362 362
 		global $wpdb;
363 363
 
364
-		$args = parent::prepare_objects_query( $request );
364
+		$args = parent::prepare_objects_query($request);
365 365
 
366 366
 		// Set post_status.
367
-		if ( in_array( $request['status'], $this->get_order_statuses(), true ) ) {
367
+		if (in_array($request['status'], $this->get_order_statuses(), true)) {
368 368
 			$args['post_status'] = 'wc-' . $request['status'];
369
-		} elseif ( 'any' === $request['status'] ) {
369
+		} elseif ('any' === $request['status']) {
370 370
 			$args['post_status'] = 'any';
371 371
 		} else {
372 372
 			$args['post_status'] = $request['status'];
373 373
 		}
374 374
 
375
-		if ( isset( $request['customer'] ) ) {
376
-			if ( ! empty( $args['meta_query'] ) ) {
375
+		if (isset($request['customer'])) {
376
+			if ( ! empty($args['meta_query'])) {
377 377
 				$args['meta_query'] = array(); // WPCS: slow query ok.
378 378
 			}
379 379
 
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 		}
386 386
 
387 387
 		// Search by product.
388
-		if ( ! empty( $request['product'] ) ) {
388
+		if ( ! empty($request['product'])) {
389 389
 			$order_ids = $wpdb->get_col(
390 390
 				$wpdb->prepare(
391 391
 					"SELECT order_id
@@ -397,18 +397,18 @@  discard block
 block discarded – undo
397 397
 			);
398 398
 
399 399
 			// Force WP_Query return empty if don't found any order.
400
-			$order_ids = ! empty( $order_ids ) ? $order_ids : array( 0 );
400
+			$order_ids = ! empty($order_ids) ? $order_ids : array(0);
401 401
 
402 402
 			$args['post__in'] = $order_ids;
403 403
 		}
404 404
 
405 405
 		// Search.
406
-		if ( ! empty( $args['s'] ) ) {
407
-			$order_ids = wc_order_search( $args['s'] );
406
+		if ( ! empty($args['s'])) {
407
+			$order_ids = wc_order_search($args['s']);
408 408
 
409
-			if ( ! empty( $order_ids ) ) {
410
-				unset( $args['s'] );
411
-				$args['post__in'] = array_merge( $order_ids, array( 0 ) );
409
+			if ( ! empty($order_ids)) {
410
+				unset($args['s']);
411
+				$args['post__in'] = array_merge($order_ids, array(0));
412 412
 			}
413 413
 		}
414 414
 
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 		 * @param array           $args    Key value array of query var to query value.
421 421
 		 * @param WP_REST_Request $request The request used.
422 422
 		 */
423
-		$args = apply_filters( 'woocommerce_rest_orders_prepare_object_query', $args, $request );
423
+		$args = apply_filters('woocommerce_rest_orders_prepare_object_query', $args, $request);
424 424
 
425 425
 		return $args;
426 426
 	}
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
 	 * @param  array $schema Schema.
432 432
 	 * @return bool
433 433
 	 */
434
-	protected function filter_writable_props( $schema ) {
435
-		return empty( $schema['readonly'] );
434
+	protected function filter_writable_props($schema) {
435
+		return empty($schema['readonly']);
436 436
 	}
437 437
 
438 438
 	/**
@@ -442,51 +442,51 @@  discard block
 block discarded – undo
442 442
 	 * @param  bool            $creating If is creating a new object.
443 443
 	 * @return WP_Error|WC_Data
444 444
 	 */
445
-	protected function prepare_object_for_database( $request, $creating = false ) {
446
-		$id        = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
447
-		$order     = new WC_Order( $id );
445
+	protected function prepare_object_for_database($request, $creating = false) {
446
+		$id        = isset($request['id']) ? absint($request['id']) : 0;
447
+		$order     = new WC_Order($id);
448 448
 		$schema    = $this->get_item_schema();
449
-		$data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );
449
+		$data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props')));
450 450
 
451 451
 		// Handle all writable props.
452
-		foreach ( $data_keys as $key ) {
453
-			$value = $request[ $key ];
452
+		foreach ($data_keys as $key) {
453
+			$value = $request[$key];
454 454
 
455
-			if ( ! is_null( $value ) ) {
456
-				switch ( $key ) {
455
+			if ( ! is_null($value)) {
456
+				switch ($key) {
457 457
 					case 'status':
458 458
 						// Status change should be done later so transitions have new data.
459 459
 						break;
460 460
 					case 'billing':
461 461
 					case 'shipping':
462
-						$this->update_address( $order, $value, $key );
462
+						$this->update_address($order, $value, $key);
463 463
 						break;
464 464
 					case 'line_items':
465 465
 					case 'shipping_lines':
466 466
 					case 'fee_lines':
467 467
 					case 'coupon_lines':
468
-						if ( is_array( $value ) ) {
469
-							foreach ( $value as $item ) {
470
-								if ( is_array( $item ) ) {
471
-									if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) {
472
-										$order->remove_item( $item['id'] );
468
+						if (is_array($value)) {
469
+							foreach ($value as $item) {
470
+								if (is_array($item)) {
471
+									if ($this->item_is_null($item) || (isset($item['quantity']) && 0 === $item['quantity'])) {
472
+										$order->remove_item($item['id']);
473 473
 									} else {
474
-										$this->set_item( $order, $key, $item );
474
+										$this->set_item($order, $key, $item);
475 475
 									}
476 476
 								}
477 477
 							}
478 478
 						}
479 479
 						break;
480 480
 					case 'meta_data':
481
-						if ( is_array( $value ) ) {
482
-							foreach ( $value as $meta ) {
483
-								$order->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
481
+						if (is_array($value)) {
482
+							foreach ($value as $meta) {
483
+								$order->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
484 484
 							}
485 485
 						}
486 486
 						break;
487 487
 					default:
488
-						if ( is_callable( array( $order, "set_{$key}" ) ) ) {
489
-							$order->{"set_{$key}"}( $value );
488
+						if (is_callable(array($order, "set_{$key}"))) {
489
+							$order->{"set_{$key}"}($value);
490 490
 						}
491 491
 						break;
492 492
 				}
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 		 * @param WP_REST_Request $request  Request object.
504 504
 		 * @param bool            $creating If is creating a new object.
505 505
 		 */
506
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $order, $request, $creating );
506
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $order, $request, $creating);
507 507
 	}
508 508
 
509 509
 	/**
@@ -515,59 +515,59 @@  discard block
 block discarded – undo
515 515
 	 * @param  bool            $creating If is creating a new object.
516 516
 	 * @return WC_Data|WP_Error
517 517
 	 */
518
-	protected function save_object( $request, $creating = false ) {
518
+	protected function save_object($request, $creating = false) {
519 519
 		try {
520
-			$object = $this->prepare_object_for_database( $request, $creating );
520
+			$object = $this->prepare_object_for_database($request, $creating);
521 521
 
522
-			if ( is_wp_error( $object ) ) {
522
+			if (is_wp_error($object)) {
523 523
 				return $object;
524 524
 			}
525 525
 
526 526
 			// Make sure gateways are loaded so hooks from gateways fire on save/create.
527 527
 			WC()->payment_gateways();
528 528
 
529
-			if ( ! is_null( $request['customer_id'] ) && 0 !== $request['customer_id'] ) {
529
+			if ( ! is_null($request['customer_id']) && 0 !== $request['customer_id']) {
530 530
 				// Make sure customer exists.
531
-				if ( false === get_user_by( 'id', $request['customer_id'] ) ) {
532
-					throw new WC_REST_Exception( 'woocommerce_rest_invalid_customer_id', __( 'Customer ID is invalid.', 'woocommerce' ), 400 );
531
+				if (false === get_user_by('id', $request['customer_id'])) {
532
+					throw new WC_REST_Exception('woocommerce_rest_invalid_customer_id', __('Customer ID is invalid.', 'woocommerce'), 400);
533 533
 				}
534 534
 
535 535
 				// Make sure customer is part of blog.
536
-				if ( is_multisite() && ! is_user_member_of_blog( $request['customer_id'] ) ) {
537
-					add_user_to_blog( get_current_blog_id(), $request['customer_id'], 'customer' );
536
+				if (is_multisite() && ! is_user_member_of_blog($request['customer_id'])) {
537
+					add_user_to_blog(get_current_blog_id(), $request['customer_id'], 'customer');
538 538
 				}
539 539
 			}
540 540
 
541
-			if ( $creating ) {
542
-				$object->set_created_via( 'rest-api' );
543
-				$object->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
541
+			if ($creating) {
542
+				$object->set_created_via('rest-api');
543
+				$object->set_prices_include_tax('yes' === get_option('woocommerce_prices_include_tax'));
544 544
 				$object->calculate_totals();
545 545
 			} else {
546 546
 				// If items have changed, recalculate order totals.
547
-				if ( isset( $request['billing'] ) || isset( $request['shipping'] ) || isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) {
548
-					$object->calculate_totals( true );
547
+				if (isset($request['billing']) || isset($request['shipping']) || isset($request['line_items']) || isset($request['shipping_lines']) || isset($request['fee_lines']) || isset($request['coupon_lines'])) {
548
+					$object->calculate_totals(true);
549 549
 				}
550 550
 			}
551 551
 
552 552
 			// Set status.
553
-			if ( ! empty( $request['status'] ) ) {
554
-				$object->set_status( $request['status'] );
553
+			if ( ! empty($request['status'])) {
554
+				$object->set_status($request['status']);
555 555
 			}
556 556
 
557 557
 			$object->save();
558 558
 
559 559
 			// Actions for after the order is saved.
560
-			if ( true === $request['set_paid'] ) {
561
-				if ( $creating || $object->needs_payment() ) {
562
-					$object->payment_complete( $request['transaction_id'] );
560
+			if (true === $request['set_paid']) {
561
+				if ($creating || $object->needs_payment()) {
562
+					$object->payment_complete($request['transaction_id']);
563 563
 				}
564 564
 			}
565 565
 
566
-			return $this->get_object( $object->get_id() );
567
-		} catch ( WC_Data_Exception $e ) {
568
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
569
-		} catch ( WC_REST_Exception $e ) {
570
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
566
+			return $this->get_object($object->get_id());
567
+		} catch (WC_Data_Exception $e) {
568
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
569
+		} catch (WC_REST_Exception $e) {
570
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
571 571
 		}
572 572
 	}
573 573
 
@@ -578,10 +578,10 @@  discard block
 block discarded – undo
578 578
 	 * @param array    $posted Posted data.
579 579
 	 * @param string   $type   Address type.
580 580
 	 */
581
-	protected function update_address( $order, $posted, $type = 'billing' ) {
582
-		foreach ( $posted as $key => $value ) {
583
-			if ( is_callable( array( $order, "set_{$type}_{$key}" ) ) ) {
584
-				$order->{"set_{$type}_{$key}"}( $value );
581
+	protected function update_address($order, $posted, $type = 'billing') {
582
+		foreach ($posted as $key => $value) {
583
+			if (is_callable(array($order, "set_{$type}_{$key}"))) {
584
+				$order->{"set_{$type}_{$key}"}($value);
585 585
 			}
586 586
 		}
587 587
 	}
@@ -593,15 +593,15 @@  discard block
 block discarded – undo
593 593
 	 * @param array $posted Request data.
594 594
 	 * @return int
595 595
 	 */
596
-	protected function get_product_id( $posted ) {
597
-		if ( ! empty( $posted['sku'] ) ) {
598
-			$product_id = (int) wc_get_product_id_by_sku( $posted['sku'] );
599
-		} elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) {
596
+	protected function get_product_id($posted) {
597
+		if ( ! empty($posted['sku'])) {
598
+			$product_id = (int) wc_get_product_id_by_sku($posted['sku']);
599
+		} elseif ( ! empty($posted['product_id']) && empty($posted['variation_id'])) {
600 600
 			$product_id = (int) $posted['product_id'];
601
-		} elseif ( ! empty( $posted['variation_id'] ) ) {
601
+		} elseif ( ! empty($posted['variation_id'])) {
602 602
 			$product_id = (int) $posted['variation_id'];
603 603
 		} else {
604
-			throw new WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce' ), 400 );
604
+			throw new WC_REST_Exception('woocommerce_rest_required_product_reference', __('Product ID or SKU is required.', 'woocommerce'), 400);
605 605
 		}
606 606
 		return $product_id;
607 607
 	}
@@ -613,9 +613,9 @@  discard block
 block discarded – undo
613 613
 	 * @param string        $prop   Order property.
614 614
 	 * @param array         $posted Request data.
615 615
 	 */
616
-	protected function maybe_set_item_prop( $item, $prop, $posted ) {
617
-		if ( isset( $posted[ $prop ] ) ) {
618
-			$item->{"set_$prop"}( $posted[ $prop ] );
616
+	protected function maybe_set_item_prop($item, $prop, $posted) {
617
+		if (isset($posted[$prop])) {
618
+			$item->{"set_$prop"}($posted[$prop]);
619 619
 		}
620 620
 	}
621 621
 
@@ -626,9 +626,9 @@  discard block
 block discarded – undo
626 626
 	 * @param string[]      $props  Properties.
627 627
 	 * @param array         $posted Request data.
628 628
 	 */
629
-	protected function maybe_set_item_props( $item, $props, $posted ) {
630
-		foreach ( $props as $prop ) {
631
-			$this->maybe_set_item_prop( $item, $prop, $posted );
629
+	protected function maybe_set_item_props($item, $props, $posted) {
630
+		foreach ($props as $prop) {
631
+			$this->maybe_set_item_prop($item, $prop, $posted);
632 632
 		}
633 633
 	}
634 634
 
@@ -638,12 +638,12 @@  discard block
 block discarded – undo
638 638
 	 * @param WC_Order_Item $item   Order item data.
639 639
 	 * @param array         $posted Request data.
640 640
 	 */
641
-	protected function maybe_set_item_meta_data( $item, $posted ) {
642
-		if ( ! empty( $posted['meta_data'] ) && is_array( $posted['meta_data'] ) ) {
643
-			foreach ( $posted['meta_data'] as $meta ) {
644
-				if ( isset( $meta['key'] ) ) {
645
-					$value = isset( $meta['value'] ) ? $meta['value'] : null;
646
-					$item->update_meta_data( $meta['key'], $value, isset( $meta['id'] ) ? $meta['id'] : '' );
641
+	protected function maybe_set_item_meta_data($item, $posted) {
642
+		if ( ! empty($posted['meta_data']) && is_array($posted['meta_data'])) {
643
+			foreach ($posted['meta_data'] as $meta) {
644
+				if (isset($meta['key'])) {
645
+					$value = isset($meta['value']) ? $meta['value'] : null;
646
+					$item->update_meta_data($meta['key'], $value, isset($meta['id']) ? $meta['id'] : '');
647 647
 				}
648 648
 			}
649 649
 		}
@@ -658,23 +658,23 @@  discard block
 block discarded – undo
658 658
 	 * @return WC_Order_Item_Product
659 659
 	 * @throws WC_REST_Exception Invalid data, server error.
660 660
 	 */
661
-	protected function prepare_line_items( $posted, $action = 'create', $item = null ) {
662
-		$item    = is_null( $item ) ? new WC_Order_Item_Product( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
663
-		$product = wc_get_product( $this->get_product_id( $posted ) );
664
-
665
-		if ( $product !== $item->get_product() ) {
666
-			$item->set_product( $product );
667
-
668
-			if ( 'create' === $action ) {
669
-				$quantity = isset( $posted['quantity'] ) ? $posted['quantity'] : 1;
670
-				$total    = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) );
671
-				$item->set_total( $total );
672
-				$item->set_subtotal( $total );
661
+	protected function prepare_line_items($posted, $action = 'create', $item = null) {
662
+		$item    = is_null($item) ? new WC_Order_Item_Product( ! empty($posted['id']) ? $posted['id'] : '') : $item;
663
+		$product = wc_get_product($this->get_product_id($posted));
664
+
665
+		if ($product !== $item->get_product()) {
666
+			$item->set_product($product);
667
+
668
+			if ('create' === $action) {
669
+				$quantity = isset($posted['quantity']) ? $posted['quantity'] : 1;
670
+				$total    = wc_get_price_excluding_tax($product, array('qty' => $quantity));
671
+				$item->set_total($total);
672
+				$item->set_subtotal($total);
673 673
 			}
674 674
 		}
675 675
 
676
-		$this->maybe_set_item_props( $item, array( 'name', 'quantity', 'total', 'subtotal', 'tax_class' ), $posted );
677
-		$this->maybe_set_item_meta_data( $item, $posted );
676
+		$this->maybe_set_item_props($item, array('name', 'quantity', 'total', 'subtotal', 'tax_class'), $posted);
677
+		$this->maybe_set_item_meta_data($item, $posted);
678 678
 
679 679
 		return $item;
680 680
 	}
@@ -688,17 +688,17 @@  discard block
 block discarded – undo
688 688
 	 * @return WC_Order_Item_Shipping
689 689
 	 * @throws WC_REST_Exception Invalid data, server error.
690 690
 	 */
691
-	protected function prepare_shipping_lines( $posted, $action = 'create', $item = null ) {
692
-		$item = is_null( $item ) ? new WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
691
+	protected function prepare_shipping_lines($posted, $action = 'create', $item = null) {
692
+		$item = is_null($item) ? new WC_Order_Item_Shipping( ! empty($posted['id']) ? $posted['id'] : '') : $item;
693 693
 
694
-		if ( 'create' === $action ) {
695
-			if ( empty( $posted['method_id'] ) ) {
696
-				throw new WC_REST_Exception( 'woocommerce_rest_invalid_shipping_item', __( 'Shipping method ID is required.', 'woocommerce' ), 400 );
694
+		if ('create' === $action) {
695
+			if (empty($posted['method_id'])) {
696
+				throw new WC_REST_Exception('woocommerce_rest_invalid_shipping_item', __('Shipping method ID is required.', 'woocommerce'), 400);
697 697
 			}
698 698
 		}
699 699
 
700
-		$this->maybe_set_item_props( $item, array( 'method_id', 'method_title', 'total' ), $posted );
701
-		$this->maybe_set_item_meta_data( $item, $posted );
700
+		$this->maybe_set_item_props($item, array('method_id', 'method_title', 'total'), $posted);
701
+		$this->maybe_set_item_meta_data($item, $posted);
702 702
 
703 703
 		return $item;
704 704
 	}
@@ -712,17 +712,17 @@  discard block
 block discarded – undo
712 712
 	 * @return WC_Order_Item_Fee
713 713
 	 * @throws WC_REST_Exception Invalid data, server error.
714 714
 	 */
715
-	protected function prepare_fee_lines( $posted, $action = 'create', $item = null ) {
716
-		$item = is_null( $item ) ? new WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
715
+	protected function prepare_fee_lines($posted, $action = 'create', $item = null) {
716
+		$item = is_null($item) ? new WC_Order_Item_Fee( ! empty($posted['id']) ? $posted['id'] : '') : $item;
717 717
 
718
-		if ( 'create' === $action ) {
719
-			if ( empty( $posted['name'] ) ) {
720
-				throw new WC_REST_Exception( 'woocommerce_rest_invalid_fee_item', __( 'Fee name is required.', 'woocommerce' ), 400 );
718
+		if ('create' === $action) {
719
+			if (empty($posted['name'])) {
720
+				throw new WC_REST_Exception('woocommerce_rest_invalid_fee_item', __('Fee name is required.', 'woocommerce'), 400);
721 721
 			}
722 722
 		}
723 723
 
724
-		$this->maybe_set_item_props( $item, array( 'name', 'tax_class', 'tax_status', 'total' ), $posted );
725
-		$this->maybe_set_item_meta_data( $item, $posted );
724
+		$this->maybe_set_item_props($item, array('name', 'tax_class', 'tax_status', 'total'), $posted);
725
+		$this->maybe_set_item_meta_data($item, $posted);
726 726
 
727 727
 		return $item;
728 728
 	}
@@ -736,17 +736,17 @@  discard block
 block discarded – undo
736 736
 	 * @return WC_Order_Item_Coupon
737 737
 	 * @throws WC_REST_Exception Invalid data, server error.
738 738
 	 */
739
-	protected function prepare_coupon_lines( $posted, $action = 'create', $item = null ) {
740
-		$item = is_null( $item ) ? new WC_Order_Item_Coupon( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
739
+	protected function prepare_coupon_lines($posted, $action = 'create', $item = null) {
740
+		$item = is_null($item) ? new WC_Order_Item_Coupon( ! empty($posted['id']) ? $posted['id'] : '') : $item;
741 741
 
742
-		if ( 'create' === $action ) {
743
-			if ( empty( $posted['code'] ) ) {
744
-				throw new WC_REST_Exception( 'woocommerce_rest_invalid_coupon_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 );
742
+		if ('create' === $action) {
743
+			if (empty($posted['code'])) {
744
+				throw new WC_REST_Exception('woocommerce_rest_invalid_coupon_coupon', __('Coupon code is required.', 'woocommerce'), 400);
745 745
 			}
746 746
 		}
747 747
 
748
-		$this->maybe_set_item_props( $item, array( 'code', 'discount' ), $posted );
749
-		$this->maybe_set_item_meta_data( $item, $posted );
748
+		$this->maybe_set_item_props($item, array('code', 'discount'), $posted);
749
+		$this->maybe_set_item_meta_data($item, $posted);
750 750
 
751 751
 		return $item;
752 752
 	}
@@ -761,10 +761,10 @@  discard block
 block discarded – undo
761 761
 	 * @param array    $posted item provided in the request body.
762 762
 	 * @throws WC_REST_Exception If item ID is not associated with order.
763 763
 	 */
764
-	protected function set_item( $order, $item_type, $posted ) {
764
+	protected function set_item($order, $item_type, $posted) {
765 765
 		global $wpdb;
766 766
 
767
-		if ( ! empty( $posted['id'] ) ) {
767
+		if ( ! empty($posted['id'])) {
768 768
 			$action = 'update';
769 769
 		} else {
770 770
 			$action = 'create';
@@ -774,22 +774,22 @@  discard block
 block discarded – undo
774 774
 		$item   = null;
775 775
 
776 776
 		// Verify provided line item ID is associated with order.
777
-		if ( 'update' === $action ) {
778
-			$item = $order->get_item( absint( $posted['id'] ), false );
777
+		if ('update' === $action) {
778
+			$item = $order->get_item(absint($posted['id']), false);
779 779
 
780
-			if ( ! $item ) {
781
-				throw new WC_REST_Exception( 'woocommerce_rest_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce' ), 400 );
780
+			if ( ! $item) {
781
+				throw new WC_REST_Exception('woocommerce_rest_invalid_item_id', __('Order item ID provided is not associated with order.', 'woocommerce'), 400);
782 782
 			}
783 783
 		}
784 784
 
785 785
 		// Prepare item data.
786
-		$item = $this->$method( $posted, $action, $item );
786
+		$item = $this->$method($posted, $action, $item);
787 787
 
788
-		do_action( 'woocommerce_rest_set_order_item', $item, $posted );
788
+		do_action('woocommerce_rest_set_order_item', $item, $posted);
789 789
 
790 790
 		// If creating the order, add the item to it.
791
-		if ( 'create' === $action ) {
792
-			$order->add_item( $item );
791
+		if ('create' === $action) {
792
+			$order->add_item($item);
793 793
 		} else {
794 794
 			$item->save();
795 795
 		}
@@ -802,11 +802,11 @@  discard block
 block discarded – undo
802 802
 	 * @param array $item Item provided in the request body.
803 803
 	 * @return bool True if the item resource ID is null, false otherwise.
804 804
 	 */
805
-	protected function item_is_null( $item ) {
806
-		$keys = array( 'product_id', 'method_id', 'method_title', 'name', 'code' );
805
+	protected function item_is_null($item) {
806
+		$keys = array('product_id', 'method_id', 'method_title', 'name', 'code');
807 807
 
808
-		foreach ( $keys as $key ) {
809
-			if ( array_key_exists( $key, $item ) && is_null( $item[ $key ] ) ) {
808
+		foreach ($keys as $key) {
809
+			if (array_key_exists($key, $item) && is_null($item[$key])) {
810 810
 				return true;
811 811
 			}
812 812
 		}
@@ -822,8 +822,8 @@  discard block
 block discarded – undo
822 822
 	protected function get_order_statuses() {
823 823
 		$order_statuses = array();
824 824
 
825
-		foreach ( array_keys( wc_get_order_statuses() ) as $status ) {
826
-			$order_statuses[] = str_replace( 'wc-', '', $status );
825
+		foreach (array_keys(wc_get_order_statuses()) as $status) {
826
+			$order_statuses[] = str_replace('wc-', '', $status);
827 827
 		}
828 828
 
829 829
 		return $order_statuses;
@@ -841,537 +841,537 @@  discard block
 block discarded – undo
841 841
 			'type'       => 'object',
842 842
 			'properties' => array(
843 843
 				'id'                   => array(
844
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
844
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
845 845
 					'type'        => 'integer',
846
-					'context'     => array( 'view', 'edit' ),
846
+					'context'     => array('view', 'edit'),
847 847
 					'readonly'    => true,
848 848
 				),
849 849
 				'parent_id'            => array(
850
-					'description' => __( 'Parent order ID.', 'woocommerce' ),
850
+					'description' => __('Parent order ID.', 'woocommerce'),
851 851
 					'type'        => 'integer',
852
-					'context'     => array( 'view', 'edit' ),
852
+					'context'     => array('view', 'edit'),
853 853
 				),
854 854
 				'number'               => array(
855
-					'description' => __( 'Order number.', 'woocommerce' ),
855
+					'description' => __('Order number.', 'woocommerce'),
856 856
 					'type'        => 'string',
857
-					'context'     => array( 'view', 'edit' ),
857
+					'context'     => array('view', 'edit'),
858 858
 					'readonly'    => true,
859 859
 				),
860 860
 				'order_key'            => array(
861
-					'description' => __( 'Order key.', 'woocommerce' ),
861
+					'description' => __('Order key.', 'woocommerce'),
862 862
 					'type'        => 'string',
863
-					'context'     => array( 'view', 'edit' ),
863
+					'context'     => array('view', 'edit'),
864 864
 					'readonly'    => true,
865 865
 				),
866 866
 				'created_via'          => array(
867
-					'description' => __( 'Shows where the order was created.', 'woocommerce' ),
867
+					'description' => __('Shows where the order was created.', 'woocommerce'),
868 868
 					'type'        => 'string',
869
-					'context'     => array( 'view', 'edit' ),
869
+					'context'     => array('view', 'edit'),
870 870
 					'readonly'    => true,
871 871
 				),
872 872
 				'version'              => array(
873
-					'description' => __( 'Version of WooCommerce which last updated the order.', 'woocommerce' ),
873
+					'description' => __('Version of WooCommerce which last updated the order.', 'woocommerce'),
874 874
 					'type'        => 'integer',
875
-					'context'     => array( 'view', 'edit' ),
875
+					'context'     => array('view', 'edit'),
876 876
 					'readonly'    => true,
877 877
 				),
878 878
 				'status'               => array(
879
-					'description' => __( 'Order status.', 'woocommerce' ),
879
+					'description' => __('Order status.', 'woocommerce'),
880 880
 					'type'        => 'string',
881 881
 					'default'     => 'pending',
882 882
 					'enum'        => $this->get_order_statuses(),
883
-					'context'     => array( 'view', 'edit' ),
883
+					'context'     => array('view', 'edit'),
884 884
 				),
885 885
 				'currency'             => array(
886
-					'description' => __( 'Currency the order was created with, in ISO format.', 'woocommerce' ),
886
+					'description' => __('Currency the order was created with, in ISO format.', 'woocommerce'),
887 887
 					'type'        => 'string',
888 888
 					'default'     => get_woocommerce_currency(),
889
-					'enum'        => array_keys( get_woocommerce_currencies() ),
890
-					'context'     => array( 'view', 'edit' ),
889
+					'enum'        => array_keys(get_woocommerce_currencies()),
890
+					'context'     => array('view', 'edit'),
891 891
 				),
892 892
 				'date_created'         => array(
893
-					'description' => __( "The date the order was created, in the site's timezone.", 'woocommerce' ),
893
+					'description' => __("The date the order was created, in the site's timezone.", 'woocommerce'),
894 894
 					'type'        => 'date-time',
895
-					'context'     => array( 'view', 'edit' ),
895
+					'context'     => array('view', 'edit'),
896 896
 					'readonly'    => true,
897 897
 				),
898 898
 				'date_created_gmt'     => array(
899
-					'description' => __( 'The date the order was created, as GMT.', 'woocommerce' ),
899
+					'description' => __('The date the order was created, as GMT.', 'woocommerce'),
900 900
 					'type'        => 'date-time',
901
-					'context'     => array( 'view', 'edit' ),
901
+					'context'     => array('view', 'edit'),
902 902
 					'readonly'    => true,
903 903
 				),
904 904
 				'date_modified'        => array(
905
-					'description' => __( "The date the order was last modified, in the site's timezone.", 'woocommerce' ),
905
+					'description' => __("The date the order was last modified, in the site's timezone.", 'woocommerce'),
906 906
 					'type'        => 'date-time',
907
-					'context'     => array( 'view', 'edit' ),
907
+					'context'     => array('view', 'edit'),
908 908
 					'readonly'    => true,
909 909
 				),
910 910
 				'date_modified_gmt'    => array(
911
-					'description' => __( 'The date the order was last modified, as GMT.', 'woocommerce' ),
911
+					'description' => __('The date the order was last modified, as GMT.', 'woocommerce'),
912 912
 					'type'        => 'date-time',
913
-					'context'     => array( 'view', 'edit' ),
913
+					'context'     => array('view', 'edit'),
914 914
 					'readonly'    => true,
915 915
 				),
916 916
 				'discount_total'       => array(
917
-					'description' => __( 'Total discount amount for the order.', 'woocommerce' ),
917
+					'description' => __('Total discount amount for the order.', 'woocommerce'),
918 918
 					'type'        => 'string',
919
-					'context'     => array( 'view', 'edit' ),
919
+					'context'     => array('view', 'edit'),
920 920
 					'readonly'    => true,
921 921
 				),
922 922
 				'discount_tax'         => array(
923
-					'description' => __( 'Total discount tax amount for the order.', 'woocommerce' ),
923
+					'description' => __('Total discount tax amount for the order.', 'woocommerce'),
924 924
 					'type'        => 'string',
925
-					'context'     => array( 'view', 'edit' ),
925
+					'context'     => array('view', 'edit'),
926 926
 					'readonly'    => true,
927 927
 				),
928 928
 				'shipping_total'       => array(
929
-					'description' => __( 'Total shipping amount for the order.', 'woocommerce' ),
929
+					'description' => __('Total shipping amount for the order.', 'woocommerce'),
930 930
 					'type'        => 'string',
931
-					'context'     => array( 'view', 'edit' ),
931
+					'context'     => array('view', 'edit'),
932 932
 					'readonly'    => true,
933 933
 				),
934 934
 				'shipping_tax'         => array(
935
-					'description' => __( 'Total shipping tax amount for the order.', 'woocommerce' ),
935
+					'description' => __('Total shipping tax amount for the order.', 'woocommerce'),
936 936
 					'type'        => 'string',
937
-					'context'     => array( 'view', 'edit' ),
937
+					'context'     => array('view', 'edit'),
938 938
 					'readonly'    => true,
939 939
 				),
940 940
 				'cart_tax'             => array(
941
-					'description' => __( 'Sum of line item taxes only.', 'woocommerce' ),
941
+					'description' => __('Sum of line item taxes only.', 'woocommerce'),
942 942
 					'type'        => 'string',
943
-					'context'     => array( 'view', 'edit' ),
943
+					'context'     => array('view', 'edit'),
944 944
 					'readonly'    => true,
945 945
 				),
946 946
 				'total'                => array(
947
-					'description' => __( 'Grand total.', 'woocommerce' ),
947
+					'description' => __('Grand total.', 'woocommerce'),
948 948
 					'type'        => 'string',
949
-					'context'     => array( 'view', 'edit' ),
949
+					'context'     => array('view', 'edit'),
950 950
 					'readonly'    => true,
951 951
 				),
952 952
 				'total_tax'            => array(
953
-					'description' => __( 'Sum of all taxes.', 'woocommerce' ),
953
+					'description' => __('Sum of all taxes.', 'woocommerce'),
954 954
 					'type'        => 'string',
955
-					'context'     => array( 'view', 'edit' ),
955
+					'context'     => array('view', 'edit'),
956 956
 					'readonly'    => true,
957 957
 				),
958 958
 				'prices_include_tax'   => array(
959
-					'description' => __( 'True the prices included tax during checkout.', 'woocommerce' ),
959
+					'description' => __('True the prices included tax during checkout.', 'woocommerce'),
960 960
 					'type'        => 'boolean',
961
-					'context'     => array( 'view', 'edit' ),
961
+					'context'     => array('view', 'edit'),
962 962
 					'readonly'    => true,
963 963
 				),
964 964
 				'customer_id'          => array(
965
-					'description' => __( 'User ID who owns the order. 0 for guests.', 'woocommerce' ),
965
+					'description' => __('User ID who owns the order. 0 for guests.', 'woocommerce'),
966 966
 					'type'        => 'integer',
967 967
 					'default'     => 0,
968
-					'context'     => array( 'view', 'edit' ),
968
+					'context'     => array('view', 'edit'),
969 969
 				),
970 970
 				'customer_ip_address'  => array(
971
-					'description' => __( "Customer's IP address.", 'woocommerce' ),
971
+					'description' => __("Customer's IP address.", 'woocommerce'),
972 972
 					'type'        => 'string',
973
-					'context'     => array( 'view', 'edit' ),
973
+					'context'     => array('view', 'edit'),
974 974
 					'readonly'    => true,
975 975
 				),
976 976
 				'customer_user_agent'  => array(
977
-					'description' => __( 'User agent of the customer.', 'woocommerce' ),
977
+					'description' => __('User agent of the customer.', 'woocommerce'),
978 978
 					'type'        => 'string',
979
-					'context'     => array( 'view', 'edit' ),
979
+					'context'     => array('view', 'edit'),
980 980
 					'readonly'    => true,
981 981
 				),
982 982
 				'customer_note'        => array(
983
-					'description' => __( 'Note left by customer during checkout.', 'woocommerce' ),
983
+					'description' => __('Note left by customer during checkout.', 'woocommerce'),
984 984
 					'type'        => 'string',
985
-					'context'     => array( 'view', 'edit' ),
985
+					'context'     => array('view', 'edit'),
986 986
 				),
987 987
 				'billing'              => array(
988
-					'description' => __( 'Billing address.', 'woocommerce' ),
988
+					'description' => __('Billing address.', 'woocommerce'),
989 989
 					'type'        => 'object',
990
-					'context'     => array( 'view', 'edit' ),
990
+					'context'     => array('view', 'edit'),
991 991
 					'properties'  => array(
992 992
 						'first_name' => array(
993
-							'description' => __( 'First name.', 'woocommerce' ),
993
+							'description' => __('First name.', 'woocommerce'),
994 994
 							'type'        => 'string',
995
-							'context'     => array( 'view', 'edit' ),
995
+							'context'     => array('view', 'edit'),
996 996
 						),
997 997
 						'last_name'  => array(
998
-							'description' => __( 'Last name.', 'woocommerce' ),
998
+							'description' => __('Last name.', 'woocommerce'),
999 999
 							'type'        => 'string',
1000
-							'context'     => array( 'view', 'edit' ),
1000
+							'context'     => array('view', 'edit'),
1001 1001
 						),
1002 1002
 						'company'    => array(
1003
-							'description' => __( 'Company name.', 'woocommerce' ),
1003
+							'description' => __('Company name.', 'woocommerce'),
1004 1004
 							'type'        => 'string',
1005
-							'context'     => array( 'view', 'edit' ),
1005
+							'context'     => array('view', 'edit'),
1006 1006
 						),
1007 1007
 						'address_1'  => array(
1008
-							'description' => __( 'Address line 1', 'woocommerce' ),
1008
+							'description' => __('Address line 1', 'woocommerce'),
1009 1009
 							'type'        => 'string',
1010
-							'context'     => array( 'view', 'edit' ),
1010
+							'context'     => array('view', 'edit'),
1011 1011
 						),
1012 1012
 						'address_2'  => array(
1013
-							'description' => __( 'Address line 2', 'woocommerce' ),
1013
+							'description' => __('Address line 2', 'woocommerce'),
1014 1014
 							'type'        => 'string',
1015
-							'context'     => array( 'view', 'edit' ),
1015
+							'context'     => array('view', 'edit'),
1016 1016
 						),
1017 1017
 						'city'       => array(
1018
-							'description' => __( 'City name.', 'woocommerce' ),
1018
+							'description' => __('City name.', 'woocommerce'),
1019 1019
 							'type'        => 'string',
1020
-							'context'     => array( 'view', 'edit' ),
1020
+							'context'     => array('view', 'edit'),
1021 1021
 						),
1022 1022
 						'state'      => array(
1023
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
1023
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
1024 1024
 							'type'        => 'string',
1025
-							'context'     => array( 'view', 'edit' ),
1025
+							'context'     => array('view', 'edit'),
1026 1026
 						),
1027 1027
 						'postcode'   => array(
1028
-							'description' => __( 'Postal code.', 'woocommerce' ),
1028
+							'description' => __('Postal code.', 'woocommerce'),
1029 1029
 							'type'        => 'string',
1030
-							'context'     => array( 'view', 'edit' ),
1030
+							'context'     => array('view', 'edit'),
1031 1031
 						),
1032 1032
 						'country'    => array(
1033
-							'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ),
1033
+							'description' => __('Country code in ISO 3166-1 alpha-2 format.', 'woocommerce'),
1034 1034
 							'type'        => 'string',
1035
-							'context'     => array( 'view', 'edit' ),
1035
+							'context'     => array('view', 'edit'),
1036 1036
 						),
1037 1037
 						'email'      => array(
1038
-							'description' => __( 'Email address.', 'woocommerce' ),
1038
+							'description' => __('Email address.', 'woocommerce'),
1039 1039
 							'type'        => 'string',
1040 1040
 							'format'      => 'email',
1041
-							'context'     => array( 'view', 'edit' ),
1041
+							'context'     => array('view', 'edit'),
1042 1042
 						),
1043 1043
 						'phone'      => array(
1044
-							'description' => __( 'Phone number.', 'woocommerce' ),
1044
+							'description' => __('Phone number.', 'woocommerce'),
1045 1045
 							'type'        => 'string',
1046
-							'context'     => array( 'view', 'edit' ),
1046
+							'context'     => array('view', 'edit'),
1047 1047
 						),
1048 1048
 					),
1049 1049
 				),
1050 1050
 				'shipping'             => array(
1051
-					'description' => __( 'Shipping address.', 'woocommerce' ),
1051
+					'description' => __('Shipping address.', 'woocommerce'),
1052 1052
 					'type'        => 'object',
1053
-					'context'     => array( 'view', 'edit' ),
1053
+					'context'     => array('view', 'edit'),
1054 1054
 					'properties'  => array(
1055 1055
 						'first_name' => array(
1056
-							'description' => __( 'First name.', 'woocommerce' ),
1056
+							'description' => __('First name.', 'woocommerce'),
1057 1057
 							'type'        => 'string',
1058
-							'context'     => array( 'view', 'edit' ),
1058
+							'context'     => array('view', 'edit'),
1059 1059
 						),
1060 1060
 						'last_name'  => array(
1061
-							'description' => __( 'Last name.', 'woocommerce' ),
1061
+							'description' => __('Last name.', 'woocommerce'),
1062 1062
 							'type'        => 'string',
1063
-							'context'     => array( 'view', 'edit' ),
1063
+							'context'     => array('view', 'edit'),
1064 1064
 						),
1065 1065
 						'company'    => array(
1066
-							'description' => __( 'Company name.', 'woocommerce' ),
1066
+							'description' => __('Company name.', 'woocommerce'),
1067 1067
 							'type'        => 'string',
1068
-							'context'     => array( 'view', 'edit' ),
1068
+							'context'     => array('view', 'edit'),
1069 1069
 						),
1070 1070
 						'address_1'  => array(
1071
-							'description' => __( 'Address line 1', 'woocommerce' ),
1071
+							'description' => __('Address line 1', 'woocommerce'),
1072 1072
 							'type'        => 'string',
1073
-							'context'     => array( 'view', 'edit' ),
1073
+							'context'     => array('view', 'edit'),
1074 1074
 						),
1075 1075
 						'address_2'  => array(
1076
-							'description' => __( 'Address line 2', 'woocommerce' ),
1076
+							'description' => __('Address line 2', 'woocommerce'),
1077 1077
 							'type'        => 'string',
1078
-							'context'     => array( 'view', 'edit' ),
1078
+							'context'     => array('view', 'edit'),
1079 1079
 						),
1080 1080
 						'city'       => array(
1081
-							'description' => __( 'City name.', 'woocommerce' ),
1081
+							'description' => __('City name.', 'woocommerce'),
1082 1082
 							'type'        => 'string',
1083
-							'context'     => array( 'view', 'edit' ),
1083
+							'context'     => array('view', 'edit'),
1084 1084
 						),
1085 1085
 						'state'      => array(
1086
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
1086
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
1087 1087
 							'type'        => 'string',
1088
-							'context'     => array( 'view', 'edit' ),
1088
+							'context'     => array('view', 'edit'),
1089 1089
 						),
1090 1090
 						'postcode'   => array(
1091
-							'description' => __( 'Postal code.', 'woocommerce' ),
1091
+							'description' => __('Postal code.', 'woocommerce'),
1092 1092
 							'type'        => 'string',
1093
-							'context'     => array( 'view', 'edit' ),
1093
+							'context'     => array('view', 'edit'),
1094 1094
 						),
1095 1095
 						'country'    => array(
1096
-							'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ),
1096
+							'description' => __('Country code in ISO 3166-1 alpha-2 format.', 'woocommerce'),
1097 1097
 							'type'        => 'string',
1098
-							'context'     => array( 'view', 'edit' ),
1098
+							'context'     => array('view', 'edit'),
1099 1099
 						),
1100 1100
 					),
1101 1101
 				),
1102 1102
 				'payment_method'       => array(
1103
-					'description' => __( 'Payment method ID.', 'woocommerce' ),
1103
+					'description' => __('Payment method ID.', 'woocommerce'),
1104 1104
 					'type'        => 'string',
1105
-					'context'     => array( 'view', 'edit' ),
1105
+					'context'     => array('view', 'edit'),
1106 1106
 				),
1107 1107
 				'payment_method_title' => array(
1108
-					'description' => __( 'Payment method title.', 'woocommerce' ),
1108
+					'description' => __('Payment method title.', 'woocommerce'),
1109 1109
 					'type'        => 'string',
1110
-					'context'     => array( 'view', 'edit' ),
1110
+					'context'     => array('view', 'edit'),
1111 1111
 					'arg_options' => array(
1112 1112
 						'sanitize_callback' => 'sanitize_text_field',
1113 1113
 					),
1114 1114
 				),
1115 1115
 				'transaction_id'       => array(
1116
-					'description' => __( 'Unique transaction ID.', 'woocommerce' ),
1116
+					'description' => __('Unique transaction ID.', 'woocommerce'),
1117 1117
 					'type'        => 'string',
1118
-					'context'     => array( 'view', 'edit' ),
1118
+					'context'     => array('view', 'edit'),
1119 1119
 				),
1120 1120
 				'date_paid'            => array(
1121
-					'description' => __( "The date the order was paid, in the site's timezone.", 'woocommerce' ),
1121
+					'description' => __("The date the order was paid, in the site's timezone.", 'woocommerce'),
1122 1122
 					'type'        => 'date-time',
1123
-					'context'     => array( 'view', 'edit' ),
1123
+					'context'     => array('view', 'edit'),
1124 1124
 					'readonly'    => true,
1125 1125
 				),
1126 1126
 				'date_paid_gmt'        => array(
1127
-					'description' => __( 'The date the order was paid, as GMT.', 'woocommerce' ),
1127
+					'description' => __('The date the order was paid, as GMT.', 'woocommerce'),
1128 1128
 					'type'        => 'date-time',
1129
-					'context'     => array( 'view', 'edit' ),
1129
+					'context'     => array('view', 'edit'),
1130 1130
 					'readonly'    => true,
1131 1131
 				),
1132 1132
 				'date_completed'       => array(
1133
-					'description' => __( "The date the order was completed, in the site's timezone.", 'woocommerce' ),
1133
+					'description' => __("The date the order was completed, in the site's timezone.", 'woocommerce'),
1134 1134
 					'type'        => 'date-time',
1135
-					'context'     => array( 'view', 'edit' ),
1135
+					'context'     => array('view', 'edit'),
1136 1136
 					'readonly'    => true,
1137 1137
 				),
1138 1138
 				'date_completed_gmt'   => array(
1139
-					'description' => __( 'The date the order was completed, as GMT.', 'woocommerce' ),
1139
+					'description' => __('The date the order was completed, as GMT.', 'woocommerce'),
1140 1140
 					'type'        => 'date-time',
1141
-					'context'     => array( 'view', 'edit' ),
1141
+					'context'     => array('view', 'edit'),
1142 1142
 					'readonly'    => true,
1143 1143
 				),
1144 1144
 				'cart_hash'            => array(
1145
-					'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ),
1145
+					'description' => __('MD5 hash of cart items to ensure orders are not modified.', 'woocommerce'),
1146 1146
 					'type'        => 'string',
1147
-					'context'     => array( 'view', 'edit' ),
1147
+					'context'     => array('view', 'edit'),
1148 1148
 					'readonly'    => true,
1149 1149
 				),
1150 1150
 				'meta_data'            => array(
1151
-					'description' => __( 'Meta data.', 'woocommerce' ),
1151
+					'description' => __('Meta data.', 'woocommerce'),
1152 1152
 					'type'        => 'array',
1153
-					'context'     => array( 'view', 'edit' ),
1153
+					'context'     => array('view', 'edit'),
1154 1154
 					'items'       => array(
1155 1155
 						'type'       => 'object',
1156 1156
 						'properties' => array(
1157 1157
 							'id'    => array(
1158
-								'description' => __( 'Meta ID.', 'woocommerce' ),
1158
+								'description' => __('Meta ID.', 'woocommerce'),
1159 1159
 								'type'        => 'integer',
1160
-								'context'     => array( 'view', 'edit' ),
1160
+								'context'     => array('view', 'edit'),
1161 1161
 								'readonly'    => true,
1162 1162
 							),
1163 1163
 							'key'   => array(
1164
-								'description' => __( 'Meta key.', 'woocommerce' ),
1164
+								'description' => __('Meta key.', 'woocommerce'),
1165 1165
 								'type'        => 'string',
1166
-								'context'     => array( 'view', 'edit' ),
1166
+								'context'     => array('view', 'edit'),
1167 1167
 							),
1168 1168
 							'value' => array(
1169
-								'description' => __( 'Meta value.', 'woocommerce' ),
1169
+								'description' => __('Meta value.', 'woocommerce'),
1170 1170
 								'type'        => 'mixed',
1171
-								'context'     => array( 'view', 'edit' ),
1171
+								'context'     => array('view', 'edit'),
1172 1172
 							),
1173 1173
 						),
1174 1174
 					),
1175 1175
 				),
1176 1176
 				'line_items'           => array(
1177
-					'description' => __( 'Line items data.', 'woocommerce' ),
1177
+					'description' => __('Line items data.', 'woocommerce'),
1178 1178
 					'type'        => 'array',
1179
-					'context'     => array( 'view', 'edit' ),
1179
+					'context'     => array('view', 'edit'),
1180 1180
 					'items'       => array(
1181 1181
 						'type'       => 'object',
1182 1182
 						'properties' => array(
1183 1183
 							'id'           => array(
1184
-								'description' => __( 'Item ID.', 'woocommerce' ),
1184
+								'description' => __('Item ID.', 'woocommerce'),
1185 1185
 								'type'        => 'integer',
1186
-								'context'     => array( 'view', 'edit' ),
1186
+								'context'     => array('view', 'edit'),
1187 1187
 								'readonly'    => true,
1188 1188
 							),
1189 1189
 							'name'         => array(
1190
-								'description' => __( 'Product name.', 'woocommerce' ),
1190
+								'description' => __('Product name.', 'woocommerce'),
1191 1191
 								'type'        => 'mixed',
1192
-								'context'     => array( 'view', 'edit' ),
1192
+								'context'     => array('view', 'edit'),
1193 1193
 							),
1194 1194
 							'product_id'   => array(
1195
-								'description' => __( 'Product ID.', 'woocommerce' ),
1195
+								'description' => __('Product ID.', 'woocommerce'),
1196 1196
 								'type'        => 'mixed',
1197
-								'context'     => array( 'view', 'edit' ),
1197
+								'context'     => array('view', 'edit'),
1198 1198
 							),
1199 1199
 							'variation_id' => array(
1200
-								'description' => __( 'Variation ID, if applicable.', 'woocommerce' ),
1200
+								'description' => __('Variation ID, if applicable.', 'woocommerce'),
1201 1201
 								'type'        => 'integer',
1202
-								'context'     => array( 'view', 'edit' ),
1202
+								'context'     => array('view', 'edit'),
1203 1203
 							),
1204 1204
 							'quantity'     => array(
1205
-								'description' => __( 'Quantity ordered.', 'woocommerce' ),
1205
+								'description' => __('Quantity ordered.', 'woocommerce'),
1206 1206
 								'type'        => 'integer',
1207
-								'context'     => array( 'view', 'edit' ),
1207
+								'context'     => array('view', 'edit'),
1208 1208
 							),
1209 1209
 							'tax_class'    => array(
1210
-								'description' => __( 'Tax class of product.', 'woocommerce' ),
1210
+								'description' => __('Tax class of product.', 'woocommerce'),
1211 1211
 								'type'        => 'string',
1212
-								'context'     => array( 'view', 'edit' ),
1212
+								'context'     => array('view', 'edit'),
1213 1213
 							),
1214 1214
 							'subtotal'     => array(
1215
-								'description' => __( 'Line subtotal (before discounts).', 'woocommerce' ),
1215
+								'description' => __('Line subtotal (before discounts).', 'woocommerce'),
1216 1216
 								'type'        => 'string',
1217
-								'context'     => array( 'view', 'edit' ),
1217
+								'context'     => array('view', 'edit'),
1218 1218
 							),
1219 1219
 							'subtotal_tax' => array(
1220
-								'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce' ),
1220
+								'description' => __('Line subtotal tax (before discounts).', 'woocommerce'),
1221 1221
 								'type'        => 'string',
1222
-								'context'     => array( 'view', 'edit' ),
1222
+								'context'     => array('view', 'edit'),
1223 1223
 								'readonly'    => true,
1224 1224
 							),
1225 1225
 							'total'        => array(
1226
-								'description' => __( 'Line total (after discounts).', 'woocommerce' ),
1226
+								'description' => __('Line total (after discounts).', 'woocommerce'),
1227 1227
 								'type'        => 'string',
1228
-								'context'     => array( 'view', 'edit' ),
1228
+								'context'     => array('view', 'edit'),
1229 1229
 							),
1230 1230
 							'total_tax'    => array(
1231
-								'description' => __( 'Line total tax (after discounts).', 'woocommerce' ),
1231
+								'description' => __('Line total tax (after discounts).', 'woocommerce'),
1232 1232
 								'type'        => 'string',
1233
-								'context'     => array( 'view', 'edit' ),
1233
+								'context'     => array('view', 'edit'),
1234 1234
 								'readonly'    => true,
1235 1235
 							),
1236 1236
 							'taxes'        => array(
1237
-								'description' => __( 'Line taxes.', 'woocommerce' ),
1237
+								'description' => __('Line taxes.', 'woocommerce'),
1238 1238
 								'type'        => 'array',
1239
-								'context'     => array( 'view', 'edit' ),
1239
+								'context'     => array('view', 'edit'),
1240 1240
 								'readonly'    => true,
1241 1241
 								'items'       => array(
1242 1242
 									'type'       => 'object',
1243 1243
 									'properties' => array(
1244 1244
 										'id'       => array(
1245
-											'description' => __( 'Tax rate ID.', 'woocommerce' ),
1245
+											'description' => __('Tax rate ID.', 'woocommerce'),
1246 1246
 											'type'        => 'integer',
1247
-											'context'     => array( 'view', 'edit' ),
1247
+											'context'     => array('view', 'edit'),
1248 1248
 										),
1249 1249
 										'total'    => array(
1250
-											'description' => __( 'Tax total.', 'woocommerce' ),
1250
+											'description' => __('Tax total.', 'woocommerce'),
1251 1251
 											'type'        => 'string',
1252
-											'context'     => array( 'view', 'edit' ),
1252
+											'context'     => array('view', 'edit'),
1253 1253
 										),
1254 1254
 										'subtotal' => array(
1255
-											'description' => __( 'Tax subtotal.', 'woocommerce' ),
1255
+											'description' => __('Tax subtotal.', 'woocommerce'),
1256 1256
 											'type'        => 'string',
1257
-											'context'     => array( 'view', 'edit' ),
1257
+											'context'     => array('view', 'edit'),
1258 1258
 										),
1259 1259
 									),
1260 1260
 								),
1261 1261
 							),
1262 1262
 							'meta_data'    => array(
1263
-								'description' => __( 'Meta data.', 'woocommerce' ),
1263
+								'description' => __('Meta data.', 'woocommerce'),
1264 1264
 								'type'        => 'array',
1265
-								'context'     => array( 'view', 'edit' ),
1265
+								'context'     => array('view', 'edit'),
1266 1266
 								'items'       => array(
1267 1267
 									'type'       => 'object',
1268 1268
 									'properties' => array(
1269 1269
 										'id'    => array(
1270
-											'description' => __( 'Meta ID.', 'woocommerce' ),
1270
+											'description' => __('Meta ID.', 'woocommerce'),
1271 1271
 											'type'        => 'integer',
1272
-											'context'     => array( 'view', 'edit' ),
1272
+											'context'     => array('view', 'edit'),
1273 1273
 											'readonly'    => true,
1274 1274
 										),
1275 1275
 										'key'   => array(
1276
-											'description' => __( 'Meta key.', 'woocommerce' ),
1276
+											'description' => __('Meta key.', 'woocommerce'),
1277 1277
 											'type'        => 'string',
1278
-											'context'     => array( 'view', 'edit' ),
1278
+											'context'     => array('view', 'edit'),
1279 1279
 										),
1280 1280
 										'value' => array(
1281
-											'description' => __( 'Meta value.', 'woocommerce' ),
1281
+											'description' => __('Meta value.', 'woocommerce'),
1282 1282
 											'type'        => 'mixed',
1283
-											'context'     => array( 'view', 'edit' ),
1283
+											'context'     => array('view', 'edit'),
1284 1284
 										),
1285 1285
 									),
1286 1286
 								),
1287 1287
 							),
1288 1288
 							'sku'          => array(
1289
-								'description' => __( 'Product SKU.', 'woocommerce' ),
1289
+								'description' => __('Product SKU.', 'woocommerce'),
1290 1290
 								'type'        => 'string',
1291
-								'context'     => array( 'view', 'edit' ),
1291
+								'context'     => array('view', 'edit'),
1292 1292
 								'readonly'    => true,
1293 1293
 							),
1294 1294
 							'price'        => array(
1295
-								'description' => __( 'Product price.', 'woocommerce' ),
1295
+								'description' => __('Product price.', 'woocommerce'),
1296 1296
 								'type'        => 'number',
1297
-								'context'     => array( 'view', 'edit' ),
1297
+								'context'     => array('view', 'edit'),
1298 1298
 								'readonly'    => true,
1299 1299
 							),
1300 1300
 						),
1301 1301
 					),
1302 1302
 				),
1303 1303
 				'tax_lines'            => array(
1304
-					'description' => __( 'Tax lines data.', 'woocommerce' ),
1304
+					'description' => __('Tax lines data.', 'woocommerce'),
1305 1305
 					'type'        => 'array',
1306
-					'context'     => array( 'view', 'edit' ),
1306
+					'context'     => array('view', 'edit'),
1307 1307
 					'readonly'    => true,
1308 1308
 					'items'       => array(
1309 1309
 						'type'       => 'object',
1310 1310
 						'properties' => array(
1311 1311
 							'id'                 => array(
1312
-								'description' => __( 'Item ID.', 'woocommerce' ),
1312
+								'description' => __('Item ID.', 'woocommerce'),
1313 1313
 								'type'        => 'integer',
1314
-								'context'     => array( 'view', 'edit' ),
1314
+								'context'     => array('view', 'edit'),
1315 1315
 								'readonly'    => true,
1316 1316
 							),
1317 1317
 							'rate_code'          => array(
1318
-								'description' => __( 'Tax rate code.', 'woocommerce' ),
1318
+								'description' => __('Tax rate code.', 'woocommerce'),
1319 1319
 								'type'        => 'string',
1320
-								'context'     => array( 'view', 'edit' ),
1320
+								'context'     => array('view', 'edit'),
1321 1321
 								'readonly'    => true,
1322 1322
 							),
1323 1323
 							'rate_id'            => array(
1324
-								'description' => __( 'Tax rate ID.', 'woocommerce' ),
1324
+								'description' => __('Tax rate ID.', 'woocommerce'),
1325 1325
 								'type'        => 'string',
1326
-								'context'     => array( 'view', 'edit' ),
1326
+								'context'     => array('view', 'edit'),
1327 1327
 								'readonly'    => true,
1328 1328
 							),
1329 1329
 							'label'              => array(
1330
-								'description' => __( 'Tax rate label.', 'woocommerce' ),
1330
+								'description' => __('Tax rate label.', 'woocommerce'),
1331 1331
 								'type'        => 'string',
1332
-								'context'     => array( 'view', 'edit' ),
1332
+								'context'     => array('view', 'edit'),
1333 1333
 								'readonly'    => true,
1334 1334
 							),
1335 1335
 							'compound'           => array(
1336
-								'description' => __( 'Show if is a compound tax rate.', 'woocommerce' ),
1336
+								'description' => __('Show if is a compound tax rate.', 'woocommerce'),
1337 1337
 								'type'        => 'boolean',
1338
-								'context'     => array( 'view', 'edit' ),
1338
+								'context'     => array('view', 'edit'),
1339 1339
 								'readonly'    => true,
1340 1340
 							),
1341 1341
 							'tax_total'          => array(
1342
-								'description' => __( 'Tax total (not including shipping taxes).', 'woocommerce' ),
1342
+								'description' => __('Tax total (not including shipping taxes).', 'woocommerce'),
1343 1343
 								'type'        => 'string',
1344
-								'context'     => array( 'view', 'edit' ),
1344
+								'context'     => array('view', 'edit'),
1345 1345
 								'readonly'    => true,
1346 1346
 							),
1347 1347
 							'shipping_tax_total' => array(
1348
-								'description' => __( 'Shipping tax total.', 'woocommerce' ),
1348
+								'description' => __('Shipping tax total.', 'woocommerce'),
1349 1349
 								'type'        => 'string',
1350
-								'context'     => array( 'view', 'edit' ),
1350
+								'context'     => array('view', 'edit'),
1351 1351
 								'readonly'    => true,
1352 1352
 							),
1353 1353
 							'meta_data'          => array(
1354
-								'description' => __( 'Meta data.', 'woocommerce' ),
1354
+								'description' => __('Meta data.', 'woocommerce'),
1355 1355
 								'type'        => 'array',
1356
-								'context'     => array( 'view', 'edit' ),
1356
+								'context'     => array('view', 'edit'),
1357 1357
 								'items'       => array(
1358 1358
 									'type'       => 'object',
1359 1359
 									'properties' => array(
1360 1360
 										'id'    => array(
1361
-											'description' => __( 'Meta ID.', 'woocommerce' ),
1361
+											'description' => __('Meta ID.', 'woocommerce'),
1362 1362
 											'type'        => 'integer',
1363
-											'context'     => array( 'view', 'edit' ),
1363
+											'context'     => array('view', 'edit'),
1364 1364
 											'readonly'    => true,
1365 1365
 										),
1366 1366
 										'key'   => array(
1367
-											'description' => __( 'Meta key.', 'woocommerce' ),
1367
+											'description' => __('Meta key.', 'woocommerce'),
1368 1368
 											'type'        => 'string',
1369
-											'context'     => array( 'view', 'edit' ),
1369
+											'context'     => array('view', 'edit'),
1370 1370
 										),
1371 1371
 										'value' => array(
1372
-											'description' => __( 'Meta value.', 'woocommerce' ),
1372
+											'description' => __('Meta value.', 'woocommerce'),
1373 1373
 											'type'        => 'mixed',
1374
-											'context'     => array( 'view', 'edit' ),
1374
+											'context'     => array('view', 'edit'),
1375 1375
 										),
1376 1376
 									),
1377 1377
 								),
@@ -1380,89 +1380,89 @@  discard block
 block discarded – undo
1380 1380
 					),
1381 1381
 				),
1382 1382
 				'shipping_lines'       => array(
1383
-					'description' => __( 'Shipping lines data.', 'woocommerce' ),
1383
+					'description' => __('Shipping lines data.', 'woocommerce'),
1384 1384
 					'type'        => 'array',
1385
-					'context'     => array( 'view', 'edit' ),
1385
+					'context'     => array('view', 'edit'),
1386 1386
 					'items'       => array(
1387 1387
 						'type'       => 'object',
1388 1388
 						'properties' => array(
1389 1389
 							'id'           => array(
1390
-								'description' => __( 'Item ID.', 'woocommerce' ),
1390
+								'description' => __('Item ID.', 'woocommerce'),
1391 1391
 								'type'        => 'integer',
1392
-								'context'     => array( 'view', 'edit' ),
1392
+								'context'     => array('view', 'edit'),
1393 1393
 								'readonly'    => true,
1394 1394
 							),
1395 1395
 							'method_title' => array(
1396
-								'description' => __( 'Shipping method name.', 'woocommerce' ),
1396
+								'description' => __('Shipping method name.', 'woocommerce'),
1397 1397
 								'type'        => 'mixed',
1398
-								'context'     => array( 'view', 'edit' ),
1398
+								'context'     => array('view', 'edit'),
1399 1399
 							),
1400 1400
 							'method_id'    => array(
1401
-								'description' => __( 'Shipping method ID.', 'woocommerce' ),
1401
+								'description' => __('Shipping method ID.', 'woocommerce'),
1402 1402
 								'type'        => 'mixed',
1403
-								'context'     => array( 'view', 'edit' ),
1403
+								'context'     => array('view', 'edit'),
1404 1404
 							),
1405 1405
 							'instance_id'  => array(
1406
-								'description' => __( 'Shipping instance ID.', 'woocommerce' ),
1406
+								'description' => __('Shipping instance ID.', 'woocommerce'),
1407 1407
 								'type'        => 'string',
1408
-								'context'     => array( 'view', 'edit' ),
1408
+								'context'     => array('view', 'edit'),
1409 1409
 							),
1410 1410
 							'total'        => array(
1411
-								'description' => __( 'Line total (after discounts).', 'woocommerce' ),
1411
+								'description' => __('Line total (after discounts).', 'woocommerce'),
1412 1412
 								'type'        => 'string',
1413
-								'context'     => array( 'view', 'edit' ),
1413
+								'context'     => array('view', 'edit'),
1414 1414
 							),
1415 1415
 							'total_tax'    => array(
1416
-								'description' => __( 'Line total tax (after discounts).', 'woocommerce' ),
1416
+								'description' => __('Line total tax (after discounts).', 'woocommerce'),
1417 1417
 								'type'        => 'string',
1418
-								'context'     => array( 'view', 'edit' ),
1418
+								'context'     => array('view', 'edit'),
1419 1419
 								'readonly'    => true,
1420 1420
 							),
1421 1421
 							'taxes'        => array(
1422
-								'description' => __( 'Line taxes.', 'woocommerce' ),
1422
+								'description' => __('Line taxes.', 'woocommerce'),
1423 1423
 								'type'        => 'array',
1424
-								'context'     => array( 'view', 'edit' ),
1424
+								'context'     => array('view', 'edit'),
1425 1425
 								'readonly'    => true,
1426 1426
 								'items'       => array(
1427 1427
 									'type'       => 'object',
1428 1428
 									'properties' => array(
1429 1429
 										'id'    => array(
1430
-											'description' => __( 'Tax rate ID.', 'woocommerce' ),
1430
+											'description' => __('Tax rate ID.', 'woocommerce'),
1431 1431
 											'type'        => 'integer',
1432
-											'context'     => array( 'view', 'edit' ),
1432
+											'context'     => array('view', 'edit'),
1433 1433
 											'readonly'    => true,
1434 1434
 										),
1435 1435
 										'total' => array(
1436
-											'description' => __( 'Tax total.', 'woocommerce' ),
1436
+											'description' => __('Tax total.', 'woocommerce'),
1437 1437
 											'type'        => 'string',
1438
-											'context'     => array( 'view', 'edit' ),
1438
+											'context'     => array('view', 'edit'),
1439 1439
 											'readonly'    => true,
1440 1440
 										),
1441 1441
 									),
1442 1442
 								),
1443 1443
 							),
1444 1444
 							'meta_data'    => array(
1445
-								'description' => __( 'Meta data.', 'woocommerce' ),
1445
+								'description' => __('Meta data.', 'woocommerce'),
1446 1446
 								'type'        => 'array',
1447
-								'context'     => array( 'view', 'edit' ),
1447
+								'context'     => array('view', 'edit'),
1448 1448
 								'items'       => array(
1449 1449
 									'type'       => 'object',
1450 1450
 									'properties' => array(
1451 1451
 										'id'    => array(
1452
-											'description' => __( 'Meta ID.', 'woocommerce' ),
1452
+											'description' => __('Meta ID.', 'woocommerce'),
1453 1453
 											'type'        => 'integer',
1454
-											'context'     => array( 'view', 'edit' ),
1454
+											'context'     => array('view', 'edit'),
1455 1455
 											'readonly'    => true,
1456 1456
 										),
1457 1457
 										'key'   => array(
1458
-											'description' => __( 'Meta key.', 'woocommerce' ),
1458
+											'description' => __('Meta key.', 'woocommerce'),
1459 1459
 											'type'        => 'string',
1460
-											'context'     => array( 'view', 'edit' ),
1460
+											'context'     => array('view', 'edit'),
1461 1461
 										),
1462 1462
 										'value' => array(
1463
-											'description' => __( 'Meta value.', 'woocommerce' ),
1463
+											'description' => __('Meta value.', 'woocommerce'),
1464 1464
 											'type'        => 'mixed',
1465
-											'context'     => array( 'view', 'edit' ),
1465
+											'context'     => array('view', 'edit'),
1466 1466
 										),
1467 1467
 									),
1468 1468
 								),
@@ -1471,96 +1471,96 @@  discard block
 block discarded – undo
1471 1471
 					),
1472 1472
 				),
1473 1473
 				'fee_lines'            => array(
1474
-					'description' => __( 'Fee lines data.', 'woocommerce' ),
1474
+					'description' => __('Fee lines data.', 'woocommerce'),
1475 1475
 					'type'        => 'array',
1476
-					'context'     => array( 'view', 'edit' ),
1476
+					'context'     => array('view', 'edit'),
1477 1477
 					'items'       => array(
1478 1478
 						'type'       => 'object',
1479 1479
 						'properties' => array(
1480 1480
 							'id'         => array(
1481
-								'description' => __( 'Item ID.', 'woocommerce' ),
1481
+								'description' => __('Item ID.', 'woocommerce'),
1482 1482
 								'type'        => 'integer',
1483
-								'context'     => array( 'view', 'edit' ),
1483
+								'context'     => array('view', 'edit'),
1484 1484
 								'readonly'    => true,
1485 1485
 							),
1486 1486
 							'name'       => array(
1487
-								'description' => __( 'Fee name.', 'woocommerce' ),
1487
+								'description' => __('Fee name.', 'woocommerce'),
1488 1488
 								'type'        => 'mixed',
1489
-								'context'     => array( 'view', 'edit' ),
1489
+								'context'     => array('view', 'edit'),
1490 1490
 							),
1491 1491
 							'tax_class'  => array(
1492
-								'description' => __( 'Tax class of fee.', 'woocommerce' ),
1492
+								'description' => __('Tax class of fee.', 'woocommerce'),
1493 1493
 								'type'        => 'string',
1494
-								'context'     => array( 'view', 'edit' ),
1494
+								'context'     => array('view', 'edit'),
1495 1495
 							),
1496 1496
 							'tax_status' => array(
1497
-								'description' => __( 'Tax status of fee.', 'woocommerce' ),
1497
+								'description' => __('Tax status of fee.', 'woocommerce'),
1498 1498
 								'type'        => 'string',
1499
-								'context'     => array( 'view', 'edit' ),
1500
-								'enum'        => array( 'taxable', 'none' ),
1499
+								'context'     => array('view', 'edit'),
1500
+								'enum'        => array('taxable', 'none'),
1501 1501
 							),
1502 1502
 							'total'      => array(
1503
-								'description' => __( 'Line total (after discounts).', 'woocommerce' ),
1503
+								'description' => __('Line total (after discounts).', 'woocommerce'),
1504 1504
 								'type'        => 'string',
1505
-								'context'     => array( 'view', 'edit' ),
1505
+								'context'     => array('view', 'edit'),
1506 1506
 							),
1507 1507
 							'total_tax'  => array(
1508
-								'description' => __( 'Line total tax (after discounts).', 'woocommerce' ),
1508
+								'description' => __('Line total tax (after discounts).', 'woocommerce'),
1509 1509
 								'type'        => 'string',
1510
-								'context'     => array( 'view', 'edit' ),
1510
+								'context'     => array('view', 'edit'),
1511 1511
 								'readonly'    => true,
1512 1512
 							),
1513 1513
 							'taxes'      => array(
1514
-								'description' => __( 'Line taxes.', 'woocommerce' ),
1514
+								'description' => __('Line taxes.', 'woocommerce'),
1515 1515
 								'type'        => 'array',
1516
-								'context'     => array( 'view', 'edit' ),
1516
+								'context'     => array('view', 'edit'),
1517 1517
 								'readonly'    => true,
1518 1518
 								'items'       => array(
1519 1519
 									'type'       => 'object',
1520 1520
 									'properties' => array(
1521 1521
 										'id'       => array(
1522
-											'description' => __( 'Tax rate ID.', 'woocommerce' ),
1522
+											'description' => __('Tax rate ID.', 'woocommerce'),
1523 1523
 											'type'        => 'integer',
1524
-											'context'     => array( 'view', 'edit' ),
1524
+											'context'     => array('view', 'edit'),
1525 1525
 											'readonly'    => true,
1526 1526
 										),
1527 1527
 										'total'    => array(
1528
-											'description' => __( 'Tax total.', 'woocommerce' ),
1528
+											'description' => __('Tax total.', 'woocommerce'),
1529 1529
 											'type'        => 'string',
1530
-											'context'     => array( 'view', 'edit' ),
1530
+											'context'     => array('view', 'edit'),
1531 1531
 											'readonly'    => true,
1532 1532
 										),
1533 1533
 										'subtotal' => array(
1534
-											'description' => __( 'Tax subtotal.', 'woocommerce' ),
1534
+											'description' => __('Tax subtotal.', 'woocommerce'),
1535 1535
 											'type'        => 'string',
1536
-											'context'     => array( 'view', 'edit' ),
1536
+											'context'     => array('view', 'edit'),
1537 1537
 											'readonly'    => true,
1538 1538
 										),
1539 1539
 									),
1540 1540
 								),
1541 1541
 							),
1542 1542
 							'meta_data'  => array(
1543
-								'description' => __( 'Meta data.', 'woocommerce' ),
1543
+								'description' => __('Meta data.', 'woocommerce'),
1544 1544
 								'type'        => 'array',
1545
-								'context'     => array( 'view', 'edit' ),
1545
+								'context'     => array('view', 'edit'),
1546 1546
 								'items'       => array(
1547 1547
 									'type'       => 'object',
1548 1548
 									'properties' => array(
1549 1549
 										'id'    => array(
1550
-											'description' => __( 'Meta ID.', 'woocommerce' ),
1550
+											'description' => __('Meta ID.', 'woocommerce'),
1551 1551
 											'type'        => 'integer',
1552
-											'context'     => array( 'view', 'edit' ),
1552
+											'context'     => array('view', 'edit'),
1553 1553
 											'readonly'    => true,
1554 1554
 										),
1555 1555
 										'key'   => array(
1556
-											'description' => __( 'Meta key.', 'woocommerce' ),
1556
+											'description' => __('Meta key.', 'woocommerce'),
1557 1557
 											'type'        => 'string',
1558
-											'context'     => array( 'view', 'edit' ),
1558
+											'context'     => array('view', 'edit'),
1559 1559
 										),
1560 1560
 										'value' => array(
1561
-											'description' => __( 'Meta value.', 'woocommerce' ),
1561
+											'description' => __('Meta value.', 'woocommerce'),
1562 1562
 											'type'        => 'mixed',
1563
-											'context'     => array( 'view', 'edit' ),
1563
+											'context'     => array('view', 'edit'),
1564 1564
 										),
1565 1565
 									),
1566 1566
 								),
@@ -1569,56 +1569,56 @@  discard block
 block discarded – undo
1569 1569
 					),
1570 1570
 				),
1571 1571
 				'coupon_lines'         => array(
1572
-					'description' => __( 'Coupons line data.', 'woocommerce' ),
1572
+					'description' => __('Coupons line data.', 'woocommerce'),
1573 1573
 					'type'        => 'array',
1574
-					'context'     => array( 'view', 'edit' ),
1574
+					'context'     => array('view', 'edit'),
1575 1575
 					'items'       => array(
1576 1576
 						'type'       => 'object',
1577 1577
 						'properties' => array(
1578 1578
 							'id'           => array(
1579
-								'description' => __( 'Item ID.', 'woocommerce' ),
1579
+								'description' => __('Item ID.', 'woocommerce'),
1580 1580
 								'type'        => 'integer',
1581
-								'context'     => array( 'view', 'edit' ),
1581
+								'context'     => array('view', 'edit'),
1582 1582
 								'readonly'    => true,
1583 1583
 							),
1584 1584
 							'code'         => array(
1585
-								'description' => __( 'Coupon code.', 'woocommerce' ),
1585
+								'description' => __('Coupon code.', 'woocommerce'),
1586 1586
 								'type'        => 'mixed',
1587
-								'context'     => array( 'view', 'edit' ),
1587
+								'context'     => array('view', 'edit'),
1588 1588
 							),
1589 1589
 							'discount'     => array(
1590
-								'description' => __( 'Discount total.', 'woocommerce' ),
1590
+								'description' => __('Discount total.', 'woocommerce'),
1591 1591
 								'type'        => 'string',
1592
-								'context'     => array( 'view', 'edit' ),
1592
+								'context'     => array('view', 'edit'),
1593 1593
 							),
1594 1594
 							'discount_tax' => array(
1595
-								'description' => __( 'Discount total tax.', 'woocommerce' ),
1595
+								'description' => __('Discount total tax.', 'woocommerce'),
1596 1596
 								'type'        => 'string',
1597
-								'context'     => array( 'view', 'edit' ),
1597
+								'context'     => array('view', 'edit'),
1598 1598
 								'readonly'    => true,
1599 1599
 							),
1600 1600
 							'meta_data'    => array(
1601
-								'description' => __( 'Meta data.', 'woocommerce' ),
1601
+								'description' => __('Meta data.', 'woocommerce'),
1602 1602
 								'type'        => 'array',
1603
-								'context'     => array( 'view', 'edit' ),
1603
+								'context'     => array('view', 'edit'),
1604 1604
 								'items'       => array(
1605 1605
 									'type'       => 'object',
1606 1606
 									'properties' => array(
1607 1607
 										'id'    => array(
1608
-											'description' => __( 'Meta ID.', 'woocommerce' ),
1608
+											'description' => __('Meta ID.', 'woocommerce'),
1609 1609
 											'type'        => 'integer',
1610
-											'context'     => array( 'view', 'edit' ),
1610
+											'context'     => array('view', 'edit'),
1611 1611
 											'readonly'    => true,
1612 1612
 										),
1613 1613
 										'key'   => array(
1614
-											'description' => __( 'Meta key.', 'woocommerce' ),
1614
+											'description' => __('Meta key.', 'woocommerce'),
1615 1615
 											'type'        => 'string',
1616
-											'context'     => array( 'view', 'edit' ),
1616
+											'context'     => array('view', 'edit'),
1617 1617
 										),
1618 1618
 										'value' => array(
1619
-											'description' => __( 'Meta value.', 'woocommerce' ),
1619
+											'description' => __('Meta value.', 'woocommerce'),
1620 1620
 											'type'        => 'mixed',
1621
-											'context'     => array( 'view', 'edit' ),
1621
+											'context'     => array('view', 'edit'),
1622 1622
 										),
1623 1623
 									),
1624 1624
 								),
@@ -1627,44 +1627,44 @@  discard block
 block discarded – undo
1627 1627
 					),
1628 1628
 				),
1629 1629
 				'refunds'              => array(
1630
-					'description' => __( 'List of refunds.', 'woocommerce' ),
1630
+					'description' => __('List of refunds.', 'woocommerce'),
1631 1631
 					'type'        => 'array',
1632
-					'context'     => array( 'view', 'edit' ),
1632
+					'context'     => array('view', 'edit'),
1633 1633
 					'readonly'    => true,
1634 1634
 					'items'       => array(
1635 1635
 						'type'       => 'object',
1636 1636
 						'properties' => array(
1637 1637
 							'id'     => array(
1638
-								'description' => __( 'Refund ID.', 'woocommerce' ),
1638
+								'description' => __('Refund ID.', 'woocommerce'),
1639 1639
 								'type'        => 'integer',
1640
-								'context'     => array( 'view', 'edit' ),
1640
+								'context'     => array('view', 'edit'),
1641 1641
 								'readonly'    => true,
1642 1642
 							),
1643 1643
 							'reason' => array(
1644
-								'description' => __( 'Refund reason.', 'woocommerce' ),
1644
+								'description' => __('Refund reason.', 'woocommerce'),
1645 1645
 								'type'        => 'string',
1646
-								'context'     => array( 'view', 'edit' ),
1646
+								'context'     => array('view', 'edit'),
1647 1647
 								'readonly'    => true,
1648 1648
 							),
1649 1649
 							'total'  => array(
1650
-								'description' => __( 'Refund total.', 'woocommerce' ),
1650
+								'description' => __('Refund total.', 'woocommerce'),
1651 1651
 								'type'        => 'string',
1652
-								'context'     => array( 'view', 'edit' ),
1652
+								'context'     => array('view', 'edit'),
1653 1653
 								'readonly'    => true,
1654 1654
 							),
1655 1655
 						),
1656 1656
 					),
1657 1657
 				),
1658 1658
 				'set_paid'             => array(
1659
-					'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce' ),
1659
+					'description' => __('Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce'),
1660 1660
 					'type'        => 'boolean',
1661 1661
 					'default'     => false,
1662
-					'context'     => array( 'edit' ),
1662
+					'context'     => array('edit'),
1663 1663
 				),
1664 1664
 			),
1665 1665
 		);
1666 1666
 
1667
-		return $this->add_additional_fields_schema( $schema );
1667
+		return $this->add_additional_fields_schema($schema);
1668 1668
 	}
1669 1669
 
1670 1670
 	/**
@@ -1675,29 +1675,29 @@  discard block
 block discarded – undo
1675 1675
 	public function get_collection_params() {
1676 1676
 		$params = parent::get_collection_params();
1677 1677
 
1678
-		$params['status']   = array(
1678
+		$params['status'] = array(
1679 1679
 			'default'           => 'any',
1680
-			'description'       => __( 'Limit result set to orders assigned a specific status.', 'woocommerce' ),
1680
+			'description'       => __('Limit result set to orders assigned a specific status.', 'woocommerce'),
1681 1681
 			'type'              => 'string',
1682
-			'enum'              => array_merge( array( 'any', 'trash' ), $this->get_order_statuses() ),
1682
+			'enum'              => array_merge(array('any', 'trash'), $this->get_order_statuses()),
1683 1683
 			'sanitize_callback' => 'sanitize_key',
1684 1684
 			'validate_callback' => 'rest_validate_request_arg',
1685 1685
 		);
1686 1686
 		$params['customer'] = array(
1687
-			'description'       => __( 'Limit result set to orders assigned a specific customer.', 'woocommerce' ),
1687
+			'description'       => __('Limit result set to orders assigned a specific customer.', 'woocommerce'),
1688 1688
 			'type'              => 'integer',
1689 1689
 			'sanitize_callback' => 'absint',
1690 1690
 			'validate_callback' => 'rest_validate_request_arg',
1691 1691
 		);
1692
-		$params['product']  = array(
1693
-			'description'       => __( 'Limit result set to orders assigned a specific product.', 'woocommerce' ),
1692
+		$params['product'] = array(
1693
+			'description'       => __('Limit result set to orders assigned a specific product.', 'woocommerce'),
1694 1694
 			'type'              => 'integer',
1695 1695
 			'sanitize_callback' => 'absint',
1696 1696
 			'validate_callback' => 'rest_validate_request_arg',
1697 1697
 		);
1698
-		$params['dp']       = array(
1698
+		$params['dp'] = array(
1699 1699
 			'default'           => wc_get_price_decimals(),
1700
-			'description'       => __( 'Number of decimal points to use in each resource.', 'woocommerce' ),
1700
+			'description'       => __('Number of decimal points to use in each resource.', 'woocommerce'),
1701 1701
 			'type'              => 'integer',
1702 1702
 			'sanitize_callback' => 'absint',
1703 1703
 			'validate_callback' => 'rest_validate_request_arg',
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-product-reviews-v2-controller.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Product Reviews Controller Class.
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
 			$this->namespace, '/' . $this->rest_base . '/batch', array(
43 43
 				'args'   => array(
44 44
 					'product_id' => array(
45
-						'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
45
+						'description' => __('Unique identifier for the variable product.', 'woocommerce'),
46 46
 						'type'        => 'integer',
47 47
 					),
48 48
 				),
49 49
 				array(
50 50
 					'methods'             => WP_REST_Server::EDITABLE,
51
-					'callback'            => array( $this, 'batch_items' ),
52
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
53
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
51
+					'callback'            => array($this, 'batch_items'),
52
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
53
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
54 54
 				),
55
-				'schema' => array( $this, 'get_public_batch_schema' ),
55
+				'schema' => array($this, 'get_public_batch_schema'),
56 56
 			)
57 57
 		);
58 58
 	}
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 	 * @param  WP_REST_Request $request Full details about the request.
64 64
 	 * @return WP_Error|boolean
65 65
 	 */
66
-	public function batch_items_permissions_check( $request ) {
67
-		if ( ! wc_rest_check_post_permissions( 'product', 'batch' ) ) {
68
-			return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
66
+	public function batch_items_permissions_check($request) {
67
+		if ( ! wc_rest_check_post_permissions('product', 'batch')) {
68
+			return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
69 69
 		}
70 70
 		return true;
71 71
 	}
@@ -77,26 +77,26 @@  discard block
 block discarded – undo
77 77
 	 * @param WP_REST_Request $request Request object.
78 78
 	 * @return WP_REST_Response $response Response data.
79 79
 	 */
80
-	public function prepare_item_for_response( $review, $request ) {
80
+	public function prepare_item_for_response($review, $request) {
81 81
 		$data = array(
82 82
 			'id'               => (int) $review->comment_ID,
83
-			'date_created'     => wc_rest_prepare_date_response( $review->comment_date ),
84
-			'date_created_gmt' => wc_rest_prepare_date_response( $review->comment_date_gmt ),
83
+			'date_created'     => wc_rest_prepare_date_response($review->comment_date),
84
+			'date_created_gmt' => wc_rest_prepare_date_response($review->comment_date_gmt),
85 85
 			'review'           => $review->comment_content,
86
-			'rating'           => (int) get_comment_meta( $review->comment_ID, 'rating', true ),
86
+			'rating'           => (int) get_comment_meta($review->comment_ID, 'rating', true),
87 87
 			'name'             => $review->comment_author,
88 88
 			'email'            => $review->comment_author_email,
89
-			'verified'         => wc_review_is_from_verified_owner( $review->comment_ID ),
89
+			'verified'         => wc_review_is_from_verified_owner($review->comment_ID),
90 90
 		);
91 91
 
92
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
93
-		$data    = $this->add_additional_fields_to_object( $data, $request );
94
-		$data    = $this->filter_response_by_context( $data, $context );
92
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
93
+		$data    = $this->add_additional_fields_to_object($data, $request);
94
+		$data    = $this->filter_response_by_context($data, $context);
95 95
 
96 96
 		// Wrap the data in a response object.
97
-		$response = rest_ensure_response( $data );
97
+		$response = rest_ensure_response($data);
98 98
 
99
-		$response->add_links( $this->prepare_links( $review, $request ) );
99
+		$response->add_links($this->prepare_links($review, $request));
100 100
 
101 101
 		/**
102 102
 		 * Filter product reviews object returned from the REST API.
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 * @param WP_Comment       $review   Product review object used to create response.
106 106
 		 * @param WP_REST_Request  $request  Request object.
107 107
 		 */
108
-		return apply_filters( 'woocommerce_rest_prepare_product_review', $response, $review, $request );
108
+		return apply_filters('woocommerce_rest_prepare_product_review', $response, $review, $request);
109 109
 	}
110 110
 
111 111
 
@@ -116,26 +116,26 @@  discard block
 block discarded – undo
116 116
 	 * @param WP_REST_Request $request Full details about the request.
117 117
 	 * @return array Of WP_Error or WP_REST_Response.
118 118
 	 */
119
-	public function batch_items( $request ) {
120
-		$items       = array_filter( $request->get_params() );
119
+	public function batch_items($request) {
120
+		$items       = array_filter($request->get_params());
121 121
 		$params      = $request->get_url_params();
122 122
 		$product_id  = $params['product_id'];
123 123
 		$body_params = array();
124 124
 
125
-		foreach ( array( 'update', 'create', 'delete' ) as $batch_type ) {
126
-			if ( ! empty( $items[ $batch_type ] ) ) {
125
+		foreach (array('update', 'create', 'delete') as $batch_type) {
126
+			if ( ! empty($items[$batch_type])) {
127 127
 				$injected_items = array();
128
-				foreach ( $items[ $batch_type ] as $item ) {
129
-					$injected_items[] = is_array( $item ) ? array_merge( array( 'product_id' => $product_id ), $item ) : $item;
128
+				foreach ($items[$batch_type] as $item) {
129
+					$injected_items[] = is_array($item) ? array_merge(array('product_id' => $product_id), $item) : $item;
130 130
 				}
131
-				$body_params[ $batch_type ] = $injected_items;
131
+				$body_params[$batch_type] = $injected_items;
132 132
 			}
133 133
 		}
134 134
 
135
-		$request = new WP_REST_Request( $request->get_method() );
136
-		$request->set_body_params( $body_params );
135
+		$request = new WP_REST_Request($request->get_method());
136
+		$request->set_body_params($body_params);
137 137
 
138
-		return parent::batch_items( $request );
138
+		return parent::batch_items($request);
139 139
 	}
140 140
 
141 141
 	/**
@@ -150,50 +150,50 @@  discard block
 block discarded – undo
150 150
 			'type'       => 'object',
151 151
 			'properties' => array(
152 152
 				'id'               => array(
153
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
153
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
154 154
 					'type'        => 'integer',
155
-					'context'     => array( 'view', 'edit' ),
155
+					'context'     => array('view', 'edit'),
156 156
 					'readonly'    => true,
157 157
 				),
158 158
 				'review'           => array(
159
-					'description' => __( 'The content of the review.', 'woocommerce' ),
159
+					'description' => __('The content of the review.', 'woocommerce'),
160 160
 					'type'        => 'string',
161
-					'context'     => array( 'view', 'edit' ),
161
+					'context'     => array('view', 'edit'),
162 162
 				),
163 163
 				'date_created'     => array(
164
-					'description' => __( "The date the review was created, in the site's timezone.", 'woocommerce' ),
164
+					'description' => __("The date the review was created, in the site's timezone.", 'woocommerce'),
165 165
 					'type'        => 'date-time',
166
-					'context'     => array( 'view', 'edit' ),
166
+					'context'     => array('view', 'edit'),
167 167
 				),
168 168
 				'date_created_gmt' => array(
169
-					'description' => __( 'The date the review was created, as GMT.', 'woocommerce' ),
169
+					'description' => __('The date the review was created, as GMT.', 'woocommerce'),
170 170
 					'type'        => 'date-time',
171
-					'context'     => array( 'view', 'edit' ),
171
+					'context'     => array('view', 'edit'),
172 172
 				),
173 173
 				'rating'           => array(
174
-					'description' => __( 'Review rating (0 to 5).', 'woocommerce' ),
174
+					'description' => __('Review rating (0 to 5).', 'woocommerce'),
175 175
 					'type'        => 'integer',
176
-					'context'     => array( 'view', 'edit' ),
176
+					'context'     => array('view', 'edit'),
177 177
 				),
178 178
 				'name'             => array(
179
-					'description' => __( 'Reviewer name.', 'woocommerce' ),
179
+					'description' => __('Reviewer name.', 'woocommerce'),
180 180
 					'type'        => 'string',
181
-					'context'     => array( 'view', 'edit' ),
181
+					'context'     => array('view', 'edit'),
182 182
 				),
183 183
 				'email'            => array(
184
-					'description' => __( 'Reviewer email.', 'woocommerce' ),
184
+					'description' => __('Reviewer email.', 'woocommerce'),
185 185
 					'type'        => 'string',
186
-					'context'     => array( 'view', 'edit' ),
186
+					'context'     => array('view', 'edit'),
187 187
 				),
188 188
 				'verified'         => array(
189
-					'description' => __( 'Shows if the reviewer bought the product or not.', 'woocommerce' ),
189
+					'description' => __('Shows if the reviewer bought the product or not.', 'woocommerce'),
190 190
 					'type'        => 'boolean',
191
-					'context'     => array( 'view', 'edit' ),
191
+					'context'     => array('view', 'edit'),
192 192
 					'readonly'    => true,
193 193
 				),
194 194
 			),
195 195
 		);
196 196
 
197
-		return $this->add_additional_fields_schema( $schema );
197
+		return $this->add_additional_fields_schema($schema);
198 198
 	}
199 199
 }
Please login to merge, or discard this patch.