@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @param int $product_id ID to delete. |
19 | 19 | */ |
20 | - public static function delete_product( $product_id ) { |
|
21 | - $product = wc_get_product( $product_id ); |
|
22 | - if ( $product ) { |
|
23 | - $product->delete( true ); |
|
20 | + public static function delete_product($product_id) { |
|
21 | + $product = wc_get_product($product_id); |
|
22 | + if ($product) { |
|
23 | + $product->delete(true); |
|
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param bool $save Save or return object. |
32 | 32 | * @return WC_Product_Simple |
33 | 33 | */ |
34 | - public static function create_simple_product( $save = true ) { |
|
34 | + public static function create_simple_product($save = true) { |
|
35 | 35 | $product = new WC_Product_Simple(); |
36 | 36 | $product->set_props( |
37 | 37 | [ |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | ] |
49 | 49 | ); |
50 | 50 | |
51 | - if ( $save ) { |
|
51 | + if ($save) { |
|
52 | 52 | $product->save(); |
53 | - return wc_get_product( $product->get_id() ); |
|
53 | + return wc_get_product($product->get_id()); |
|
54 | 54 | } else { |
55 | 55 | return $product; |
56 | 56 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | ); |
76 | 76 | $product->save(); |
77 | 77 | |
78 | - return wc_get_product( $product->get_id() ); |
|
78 | + return wc_get_product($product->get_id()); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | 'sku' => 'DUMMY GROUPED SKU', |
95 | 95 | ] |
96 | 96 | ); |
97 | - $product->set_children( [ $simple_product_1->get_id(), $simple_product_2->get_id() ] ); |
|
97 | + $product->set_children([$simple_product_1->get_id(), $simple_product_2->get_id()]); |
|
98 | 98 | $product->save(); |
99 | 99 | |
100 | - return wc_get_product( $product->get_id() ); |
|
100 | + return wc_get_product($product->get_id()); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -119,36 +119,36 @@ discard block |
||
119 | 119 | $attributes = []; |
120 | 120 | |
121 | 121 | $attribute = new WC_Product_Attribute(); |
122 | - $attribute_data = self::create_attribute( 'size', [ 'small', 'large', 'huge' ] ); |
|
123 | - $attribute->set_id( $attribute_data['attribute_id'] ); |
|
124 | - $attribute->set_name( $attribute_data['attribute_taxonomy'] ); |
|
125 | - $attribute->set_options( $attribute_data['term_ids'] ); |
|
126 | - $attribute->set_position( 1 ); |
|
127 | - $attribute->set_visible( true ); |
|
128 | - $attribute->set_variation( true ); |
|
122 | + $attribute_data = self::create_attribute('size', ['small', 'large', 'huge']); |
|
123 | + $attribute->set_id($attribute_data['attribute_id']); |
|
124 | + $attribute->set_name($attribute_data['attribute_taxonomy']); |
|
125 | + $attribute->set_options($attribute_data['term_ids']); |
|
126 | + $attribute->set_position(1); |
|
127 | + $attribute->set_visible(true); |
|
128 | + $attribute->set_variation(true); |
|
129 | 129 | $attributes[] = $attribute; |
130 | 130 | |
131 | 131 | $attribute = new WC_Product_Attribute(); |
132 | - $attribute_data = self::create_attribute( 'colour', [ 'red', 'blue' ] ); |
|
133 | - $attribute->set_id( $attribute_data['attribute_id'] ); |
|
134 | - $attribute->set_name( $attribute_data['attribute_taxonomy'] ); |
|
135 | - $attribute->set_options( $attribute_data['term_ids'] ); |
|
136 | - $attribute->set_position( 1 ); |
|
137 | - $attribute->set_visible( true ); |
|
138 | - $attribute->set_variation( true ); |
|
132 | + $attribute_data = self::create_attribute('colour', ['red', 'blue']); |
|
133 | + $attribute->set_id($attribute_data['attribute_id']); |
|
134 | + $attribute->set_name($attribute_data['attribute_taxonomy']); |
|
135 | + $attribute->set_options($attribute_data['term_ids']); |
|
136 | + $attribute->set_position(1); |
|
137 | + $attribute->set_visible(true); |
|
138 | + $attribute->set_variation(true); |
|
139 | 139 | $attributes[] = $attribute; |
140 | 140 | |
141 | 141 | $attribute = new WC_Product_Attribute(); |
142 | - $attribute_data = self::create_attribute( 'number', [ '0', '1', '2' ] ); |
|
143 | - $attribute->set_id( $attribute_data['attribute_id'] ); |
|
144 | - $attribute->set_name( $attribute_data['attribute_taxonomy'] ); |
|
145 | - $attribute->set_options( $attribute_data['term_ids'] ); |
|
146 | - $attribute->set_position( 1 ); |
|
147 | - $attribute->set_visible( true ); |
|
148 | - $attribute->set_variation( true ); |
|
142 | + $attribute_data = self::create_attribute('number', ['0', '1', '2']); |
|
143 | + $attribute->set_id($attribute_data['attribute_id']); |
|
144 | + $attribute->set_name($attribute_data['attribute_taxonomy']); |
|
145 | + $attribute->set_options($attribute_data['term_ids']); |
|
146 | + $attribute->set_position(1); |
|
147 | + $attribute->set_visible(true); |
|
148 | + $attribute->set_variation(true); |
|
149 | 149 | $attributes[] = $attribute; |
150 | 150 | |
151 | - $product->set_attributes( $attributes ); |
|
151 | + $product->set_attributes($attributes); |
|
152 | 152 | $product->save(); |
153 | 153 | |
154 | 154 | $variation_1 = new WC_Product_Variation(); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | 'regular_price' => 10, |
160 | 160 | ] |
161 | 161 | ); |
162 | - $variation_1->set_attributes( [ 'pa_size' => 'small' ] ); |
|
162 | + $variation_1->set_attributes(['pa_size' => 'small']); |
|
163 | 163 | $variation_1->save(); |
164 | 164 | |
165 | 165 | $variation_2 = new WC_Product_Variation(); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | 'regular_price' => 15, |
171 | 171 | ] |
172 | 172 | ); |
173 | - $variation_2->set_attributes( [ 'pa_size' => 'large' ] ); |
|
173 | + $variation_2->set_attributes(['pa_size' => 'large']); |
|
174 | 174 | $variation_2->save(); |
175 | 175 | |
176 | 176 | $variation_3 = new WC_Product_Variation(); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | ); |
208 | 208 | $variation_4->save(); |
209 | 209 | |
210 | - return wc_get_product( $product->get_id() ); |
|
210 | + return wc_get_product($product->get_id()); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -219,30 +219,30 @@ discard block |
||
219 | 219 | * @param array(string) $terms Terms to create for the attribute. |
220 | 220 | * @return array |
221 | 221 | */ |
222 | - public static function create_attribute( $raw_name = 'size', $terms = [ 'small' ] ) { |
|
222 | + public static function create_attribute($raw_name = 'size', $terms = ['small']) { |
|
223 | 223 | global $wpdb, $wc_product_attributes; |
224 | 224 | |
225 | 225 | // Make sure caches are clean. |
226 | - delete_transient( 'wc_attribute_taxonomies' ); |
|
227 | - if ( is_callable( [ 'WC_Cache_Helper', 'invalidate_cache_group' ] ) ) { |
|
226 | + delete_transient('wc_attribute_taxonomies'); |
|
227 | + if (is_callable(['WC_Cache_Helper', 'invalidate_cache_group'])) { |
|
228 | 228 | WC_Cache_Helper::invalidate_cache_group('woocommerce-attributes'); |
229 | 229 | } |
230 | 230 | |
231 | 231 | // These are exported as labels, so convert the label to a name if possible first. |
232 | - $attribute_labels = wp_list_pluck( wc_get_attribute_taxonomies(), 'attribute_label', 'attribute_name' ); |
|
233 | - $attribute_name = array_search( $raw_name, $attribute_labels, true ); |
|
232 | + $attribute_labels = wp_list_pluck(wc_get_attribute_taxonomies(), 'attribute_label', 'attribute_name'); |
|
233 | + $attribute_name = array_search($raw_name, $attribute_labels, true); |
|
234 | 234 | |
235 | - if ( ! $attribute_name ) { |
|
236 | - $attribute_name = wc_sanitize_taxonomy_name( $raw_name ); |
|
235 | + if ( ! $attribute_name) { |
|
236 | + $attribute_name = wc_sanitize_taxonomy_name($raw_name); |
|
237 | 237 | } |
238 | 238 | |
239 | - $attribute_id = wc_attribute_taxonomy_id_by_name( $attribute_name ); |
|
239 | + $attribute_id = wc_attribute_taxonomy_id_by_name($attribute_name); |
|
240 | 240 | |
241 | - if ( ! $attribute_id ) { |
|
242 | - $taxonomy_name = wc_attribute_taxonomy_name( $attribute_name ); |
|
241 | + if ( ! $attribute_id) { |
|
242 | + $taxonomy_name = wc_attribute_taxonomy_name($attribute_name); |
|
243 | 243 | |
244 | 244 | // Degister taxonomy which other tests may have created... |
245 | - unregister_taxonomy( $taxonomy_name ); |
|
245 | + unregister_taxonomy($taxonomy_name); |
|
246 | 246 | |
247 | 247 | $attribute_id = wc_create_attribute( |
248 | 248 | [ |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | // Register as taxonomy. |
258 | 258 | register_taxonomy( |
259 | 259 | $taxonomy_name, |
260 | - apply_filters( 'woocommerce_taxonomy_objects_' . $taxonomy_name, [ 'product' ] ), |
|
260 | + apply_filters('woocommerce_taxonomy_objects_' . $taxonomy_name, ['product']), |
|
261 | 261 | apply_filters( |
262 | 262 | 'woocommerce_taxonomy_args_' . $taxonomy_name, |
263 | 263 | [ |
@@ -275,12 +275,12 @@ discard block |
||
275 | 275 | // Set product attributes global. |
276 | 276 | $wc_product_attributes = []; |
277 | 277 | |
278 | - foreach ( wc_get_attribute_taxonomies() as $taxonomy ) { |
|
279 | - $wc_product_attributes[ wc_attribute_taxonomy_name( $taxonomy->attribute_name ) ] = $taxonomy; |
|
278 | + foreach (wc_get_attribute_taxonomies() as $taxonomy) { |
|
279 | + $wc_product_attributes[wc_attribute_taxonomy_name($taxonomy->attribute_name)] = $taxonomy; |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
283 | - $attribute = wc_get_attribute( $attribute_id ); |
|
283 | + $attribute = wc_get_attribute($attribute_id); |
|
284 | 284 | $return = [ |
285 | 285 | 'attribute_name' => $attribute->name, |
286 | 286 | 'attribute_taxonomy' => $attribute->slug, |
@@ -288,11 +288,11 @@ discard block |
||
288 | 288 | 'term_ids' => [], |
289 | 289 | ]; |
290 | 290 | |
291 | - foreach ( $terms as $term ) { |
|
292 | - $result = term_exists( $term, $attribute->slug ); |
|
291 | + foreach ($terms as $term) { |
|
292 | + $result = term_exists($term, $attribute->slug); |
|
293 | 293 | |
294 | - if ( ! $result ) { |
|
295 | - $result = wp_insert_term( $term, $attribute->slug ); |
|
294 | + if ( ! $result) { |
|
295 | + $result = wp_insert_term($term, $attribute->slug); |
|
296 | 296 | $return['term_ids'][] = $result['term_id']; |
297 | 297 | } else { |
298 | 298 | $return['term_ids'][] = $result['term_id']; |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @since 2.3 |
311 | 311 | */ |
312 | - public static function delete_attribute( $attribute_id ) { |
|
312 | + public static function delete_attribute($attribute_id) { |
|
313 | 313 | global $wpdb; |
314 | 314 | |
315 | - $attribute_id = absint( $attribute_id ); |
|
315 | + $attribute_id = absint($attribute_id); |
|
316 | 316 | |
317 | 317 | $wpdb->query( |
318 | - $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = %d", $attribute_id ) |
|
318 | + $wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = %d", $attribute_id) |
|
319 | 319 | ); |
320 | 320 | } |
321 | 321 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | * @param string $review_content string Content to use for the product review. |
328 | 328 | * @return integer Product Review ID. |
329 | 329 | */ |
330 | - public static function create_product_review( $product_id, $review_content = 'Review content here' ) { |
|
330 | + public static function create_product_review($product_id, $review_content = 'Review content here') { |
|
331 | 331 | $data = [ |
332 | 332 | 'comment_post_ID' => $product_id, |
333 | 333 | 'comment_author' => 'admin', |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | 'comment_approved' => 1, |
339 | 339 | 'comment_type' => 'review', |
340 | 340 | ]; |
341 | - return wp_insert_comment( $data ); |
|
341 | + return wp_insert_comment($data); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @param int $id ID to update. |
349 | 349 | */ |
350 | - public static function save_post_test_update_meta_data_direct( $id ) { |
|
351 | - update_post_meta( $id, '_test2', 'world' ); |
|
350 | + public static function save_post_test_update_meta_data_direct($id) { |
|
351 | + update_post_meta($id, '_test2', 'world'); |
|
352 | 352 | } |
353 | 353 | } |