Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like WC_Coupon often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WC_Coupon, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class WC_Coupon extends WC_Legacy_Coupon { |
||
20 | |||
21 | /** |
||
22 | * Data array, with defaults. |
||
23 | * @since 2.7.0 |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $_data = array( |
||
27 | 'id' => 0, |
||
28 | 'code' => '', |
||
29 | 'amount' => 0, |
||
30 | 'date_created' => '', |
||
31 | 'date_modified' => '', |
||
32 | 'discount_type' => 'fixed_cart', |
||
33 | 'description' => '', |
||
34 | 'date_expires' => '', |
||
35 | 'usage_count' => 0, |
||
36 | 'individual_use' => false, |
||
37 | 'product_ids' => array(), |
||
38 | 'excluded_product_ids' => array(), |
||
39 | 'usage_limit' => 0, |
||
40 | 'usage_limit_per_user' => 0, |
||
41 | 'limit_usage_to_x_items' => 0, |
||
42 | 'free_shipping' => false, |
||
43 | 'product_categories' => array(), |
||
44 | 'excluded_product_categories' => array(), |
||
45 | 'exclude_sale_items' => false, |
||
46 | 'minimum_amount' => '', |
||
47 | 'maximum_amount' => '', |
||
48 | 'email_restrictions' => array(), |
||
49 | 'used_by' => '', |
||
50 | ); |
||
51 | |||
52 | // Coupon message codes |
||
53 | const E_WC_COUPON_INVALID_FILTERED = 100; |
||
54 | const E_WC_COUPON_INVALID_REMOVED = 101; |
||
55 | const E_WC_COUPON_NOT_YOURS_REMOVED = 102; |
||
56 | const E_WC_COUPON_ALREADY_APPLIED = 103; |
||
57 | const E_WC_COUPON_ALREADY_APPLIED_INDIV_USE_ONLY = 104; |
||
58 | const E_WC_COUPON_NOT_EXIST = 105; |
||
59 | const E_WC_COUPON_USAGE_LIMIT_REACHED = 106; |
||
60 | const E_WC_COUPON_EXPIRED = 107; |
||
61 | const E_WC_COUPON_MIN_SPEND_LIMIT_NOT_MET = 108; |
||
62 | const E_WC_COUPON_NOT_APPLICABLE = 109; |
||
63 | const E_WC_COUPON_NOT_VALID_SALE_ITEMS = 110; |
||
64 | const E_WC_COUPON_PLEASE_ENTER = 111; |
||
65 | const E_WC_COUPON_MAX_SPEND_LIMIT_MET = 112; |
||
66 | const E_WC_COUPON_EXCLUDED_PRODUCTS = 113; |
||
67 | const E_WC_COUPON_EXCLUDED_CATEGORIES = 114; |
||
68 | const WC_COUPON_SUCCESS = 200; |
||
69 | const WC_COUPON_REMOVED = 201; |
||
70 | |||
71 | /** |
||
72 | * Internal meta type used to store coupon data. |
||
73 | * @since 2.7.0 |
||
74 | * @var string |
||
75 | */ |
||
76 | protected $_meta_type = 'post'; |
||
77 | |||
78 | /** |
||
79 | * Data stored in meta keys, but not considered "meta" for a coupon. |
||
80 | * @since 2.7.0 |
||
81 | * @var array |
||
82 | */ |
||
83 | protected $_internal_meta_keys = array( |
||
84 | 'discount_type', 'coupon_amount', 'expiry_date', 'usage_count', |
||
85 | 'individual_use', 'product_ids', 'exclude_product_ids', 'usage_limit', |
||
86 | 'usage_limit_per_user', 'limit_usage_to_x_items', 'free_shipping', |
||
87 | 'product_categories', 'exclude_product_categories', 'exclude_sale_items', |
||
88 | 'minimum_amount', 'maximum_amount', 'customer_email', '_used_by', |
||
89 | '_edit_lock', '_edit_last', |
||
90 | ); |
||
91 | |||
92 | /** |
||
93 | * Coupon constructor. Loads coupon data. |
||
94 | * @param mixed $data Coupon data, object, ID or code. |
||
95 | */ |
||
96 | public function __construct( $data = '' ) { |
||
111 | |||
112 | /** |
||
113 | * Checks the coupon type. |
||
114 | * @param string $type Array or string of types |
||
115 | * @return bool |
||
116 | */ |
||
117 | public function is_type( $type ) { |
||
120 | |||
121 | /* |
||
122 | |-------------------------------------------------------------------------- |
||
123 | | Getters |
||
124 | |-------------------------------------------------------------------------- |
||
125 | | |
||
126 | | Methods for getting data from the coupon object. |
||
127 | | |
||
128 | */ |
||
129 | |||
130 | /** |
||
131 | * Get coupon ID. |
||
132 | * @since 2.7.0 |
||
133 | * @return integer |
||
134 | */ |
||
135 | public function get_id() { |
||
138 | |||
139 | /** |
||
140 | * Get coupon code. |
||
141 | * @since 2.7.0 |
||
142 | * @return string |
||
143 | */ |
||
144 | public function get_code() { |
||
147 | |||
148 | /** |
||
149 | * Get coupon description. |
||
150 | * @since 2.7.0 |
||
151 | * @return string |
||
152 | */ |
||
153 | public function get_description() { |
||
156 | |||
157 | /** |
||
158 | * Get discount type. |
||
159 | * @since 2.7.0 |
||
160 | * @return string |
||
161 | */ |
||
162 | public function get_discount_type() { |
||
165 | |||
166 | /** |
||
167 | * Get coupon code. |
||
168 | * @since 2.7.0 |
||
169 | * @return float |
||
170 | */ |
||
171 | public function get_amount() { |
||
174 | |||
175 | /** |
||
176 | * Get coupon expiration date. |
||
177 | * @since 2.7.0 |
||
178 | * @return int |
||
179 | */ |
||
180 | public function get_date_expires() { |
||
183 | |||
184 | /** |
||
185 | * Get date_created |
||
186 | * @since 2.7.0 |
||
187 | * @return int |
||
188 | */ |
||
189 | public function get_date_created() { |
||
192 | |||
193 | /** |
||
194 | * Get date_modified |
||
195 | * @since 2.7.0 |
||
196 | * @return int |
||
197 | */ |
||
198 | public function get_date_modified() { |
||
201 | |||
202 | /** |
||
203 | * Get coupon usage count. |
||
204 | * @since 2.7.0 |
||
205 | * @return integer |
||
206 | */ |
||
207 | public function get_usage_count() { |
||
210 | |||
211 | /** |
||
212 | * Get the "indvidual use" checkbox status. |
||
213 | * @since 2.7.0 |
||
214 | * @return bool |
||
215 | */ |
||
216 | public function get_individual_use() { |
||
219 | |||
220 | /** |
||
221 | * Get product IDs this coupon can apply to. |
||
222 | * @since 2.7.0 |
||
223 | * @return array |
||
224 | */ |
||
225 | public function get_product_ids() { |
||
228 | |||
229 | /** |
||
230 | * Get product IDs that this coupon should not apply to. |
||
231 | * @since 2.7.0 |
||
232 | * @return array |
||
233 | */ |
||
234 | public function get_excluded_product_ids() { |
||
237 | |||
238 | /** |
||
239 | * Get coupon usage limit. |
||
240 | * @since 2.7.0 |
||
241 | * @return integer |
||
242 | */ |
||
243 | public function get_usage_limit() { |
||
246 | |||
247 | /** |
||
248 | * Get coupon usage limit per customer (for a single customer) |
||
249 | * @since 2.7.0 |
||
250 | * @return integer |
||
251 | */ |
||
252 | public function get_usage_limit_per_user() { |
||
255 | |||
256 | /** |
||
257 | * Usage limited to certain amount of items |
||
258 | * @since 2.7.0 |
||
259 | * @return integer |
||
260 | */ |
||
261 | public function get_limit_usage_to_x_items() { |
||
264 | |||
265 | /** |
||
266 | * If this coupon grants free shipping or not. |
||
267 | * @since 2.7.0 |
||
268 | * @return bool |
||
269 | */ |
||
270 | public function get_free_shipping() { |
||
273 | |||
274 | /** |
||
275 | * Get product categories this coupon can apply to. |
||
276 | * @since 2.7.0 |
||
277 | * @return array |
||
278 | */ |
||
279 | public function get_product_categories() { |
||
282 | |||
283 | /** |
||
284 | * Get product categories this coupon cannot not apply to. |
||
285 | * @since 2.7.0 |
||
286 | * @return array |
||
287 | */ |
||
288 | public function get_excluded_product_categories() { |
||
291 | |||
292 | /** |
||
293 | * If this coupon should exclude items on sale. |
||
294 | * @since 2.7.0 |
||
295 | * @return bool |
||
296 | */ |
||
297 | public function get_exclude_sale_items() { |
||
300 | |||
301 | /** |
||
302 | * Get minium spend amount. |
||
303 | * @since 2.7.0 |
||
304 | * @return float |
||
305 | */ |
||
306 | public function get_minimum_amount() { |
||
309 | /** |
||
310 | * Get maximum spend amount. |
||
311 | * @since 2.7.0 |
||
312 | * @return float |
||
313 | */ |
||
314 | public function get_maximum_amount() { |
||
317 | |||
318 | /** |
||
319 | * Get emails to check customer usage restrictions. |
||
320 | * @since 2.7.0 |
||
321 | * @return array |
||
322 | */ |
||
323 | public function get_email_restrictions() { |
||
326 | |||
327 | /** |
||
328 | * Get records of all users who have used the current coupon. |
||
329 | * |
||
330 | * @return array |
||
331 | */ |
||
332 | public function get_used_by() { |
||
335 | |||
336 | /** |
||
337 | * Get a coupon ID from it's code. |
||
338 | * @since 2.5.0 woocommerce_coupon_code_query was removed in favour of woocommerce_get_coupon_id_from_code filter on the return. wp_cache was also implemented. |
||
339 | * @param string $code |
||
340 | * @return int |
||
341 | */ |
||
342 | private function get_coupon_id_from_code( $code ) { |
||
356 | |||
357 | /** |
||
358 | * Get discount amount for a cart item. |
||
359 | * |
||
360 | * @param float $discounting_amount Amount the coupon is being applied to |
||
361 | * @param array|null $cart_item Cart item being discounted if applicable |
||
362 | * @param boolean $single True if discounting a single qty item, false if its the line |
||
363 | * @return float Amount this coupon has discounted |
||
364 | */ |
||
365 | public function get_discount_amount( $discounting_amount, $cart_item = null, $single = false ) { |
||
416 | |||
417 | /* |
||
418 | |-------------------------------------------------------------------------- |
||
419 | | Setters |
||
420 | |-------------------------------------------------------------------------- |
||
421 | | |
||
422 | | Functions for setting coupon data. These should not update anything in the |
||
423 | | database itself and should only change what is stored in the class |
||
424 | | object. |
||
425 | | |
||
426 | */ |
||
427 | |||
428 | /** |
||
429 | * Set ID |
||
430 | * @param int $value |
||
431 | * @throws WC_Data_Exception |
||
432 | */ |
||
433 | public function set_id( $value ) { |
||
436 | |||
437 | /** |
||
438 | * Set coupon code. |
||
439 | * @since 2.7.0 |
||
440 | * @param string $code |
||
441 | * @throws WC_Data_Exception |
||
442 | */ |
||
443 | public function set_code( $code ) { |
||
446 | |||
447 | /** |
||
448 | * Set coupon description. |
||
449 | * @since 2.7.0 |
||
450 | * @param string $description |
||
451 | * @throws WC_Data_Exception |
||
452 | */ |
||
453 | public function set_description( $description ) { |
||
456 | |||
457 | /** |
||
458 | * Set discount type. |
||
459 | * @since 2.7.0 |
||
460 | * @param string $discount_type |
||
461 | * @throws WC_Data_Exception |
||
462 | */ |
||
463 | public function set_discount_type( $discount_type ) { |
||
469 | |||
470 | /** |
||
471 | * Set amount. |
||
472 | * @since 2.7.0 |
||
473 | * @param float $amount |
||
474 | * @throws WC_Data_Exception |
||
475 | */ |
||
476 | public function set_amount( $amount ) { |
||
479 | |||
480 | /** |
||
481 | * Set expiration date. |
||
482 | * @since 2.7.0 |
||
483 | * @param string $timestamp Timestamp |
||
484 | * @throws WC_Data_Exception |
||
485 | */ |
||
486 | public function set_date_expires( $timestamp ) { |
||
489 | |||
490 | /** |
||
491 | * Set date_created |
||
492 | * @since 2.7.0 |
||
493 | * @param string $timestamp Timestamp |
||
494 | * @throws WC_Data_Exception |
||
495 | */ |
||
496 | public function set_date_created( $timestamp ) { |
||
499 | |||
500 | /** |
||
501 | * Set date_modified |
||
502 | * @since 2.7.0 |
||
503 | * @param string $timestamp |
||
504 | * @throws WC_Data_Exception |
||
505 | */ |
||
506 | public function set_date_modified( $timestamp ) { |
||
509 | |||
510 | /** |
||
511 | * Set how many times this coupon has been used. |
||
512 | * @since 2.7.0 |
||
513 | * @param int $usage_count |
||
514 | * @throws WC_Data_Exception |
||
515 | */ |
||
516 | public function set_usage_count( $usage_count ) { |
||
519 | |||
520 | /** |
||
521 | * Set if this coupon can only be used once. |
||
522 | * @since 2.7.0 |
||
523 | * @param bool $is_individual_use |
||
524 | * @throws WC_Data_Exception |
||
525 | */ |
||
526 | public function set_individual_use( $is_individual_use ) { |
||
529 | |||
530 | /** |
||
531 | * Set the product IDs this coupon can be used with. |
||
532 | * @since 2.7.0 |
||
533 | * @param array $product_ids |
||
534 | * @throws WC_Data_Exception |
||
535 | */ |
||
536 | public function set_product_ids( $product_ids ) { |
||
539 | |||
540 | /** |
||
541 | * Set the product IDs this coupon cannot be used with. |
||
542 | * @since 2.7.0 |
||
543 | * @param array $excluded_product_ids |
||
544 | * @throws WC_Data_Exception |
||
545 | */ |
||
546 | public function set_excluded_product_ids( $excluded_product_ids ) { |
||
549 | |||
550 | /** |
||
551 | * Set the amount of times this coupon can be used. |
||
552 | * @since 2.7.0 |
||
553 | * @param int $usage_limit |
||
554 | * @throws WC_Data_Exception |
||
555 | */ |
||
556 | public function set_usage_limit( $usage_limit ) { |
||
559 | |||
560 | /** |
||
561 | * Set the amount of times this coupon can be used per user. |
||
562 | * @since 2.7.0 |
||
563 | * @param int $usage_limit |
||
564 | * @throws WC_Data_Exception |
||
565 | */ |
||
566 | public function set_usage_limit_per_user( $usage_limit ) { |
||
569 | |||
570 | /** |
||
571 | * Set usage limit to x number of items. |
||
572 | * @since 2.7.0 |
||
573 | * @param int $limit_usage_to_x_items |
||
574 | * @throws WC_Data_Exception |
||
575 | */ |
||
576 | public function set_limit_usage_to_x_items( $limit_usage_to_x_items ) { |
||
579 | |||
580 | /** |
||
581 | * Set if this coupon enables free shipping or not. |
||
582 | * @since 2.7.0 |
||
583 | * @param bool $free_shipping |
||
584 | * @throws WC_Data_Exception |
||
585 | */ |
||
586 | public function set_free_shipping( $free_shipping ) { |
||
589 | |||
590 | /** |
||
591 | * Set the product category IDs this coupon can be used with. |
||
592 | * @since 2.7.0 |
||
593 | * @param array $product_categories |
||
594 | * @throws WC_Data_Exception |
||
595 | */ |
||
596 | public function set_product_categories( $product_categories ) { |
||
599 | |||
600 | /** |
||
601 | * Set the product category IDs this coupon cannot be used with. |
||
602 | * @since 2.7.0 |
||
603 | * @param array $excluded_product_categories |
||
604 | * @throws WC_Data_Exception |
||
605 | */ |
||
606 | public function set_excluded_product_categories( $excluded_product_categories ) { |
||
609 | |||
610 | /** |
||
611 | * Set if this coupon should excluded sale items or not. |
||
612 | * @since 2.7.0 |
||
613 | * @param bool $exclude_sale_items |
||
614 | * @throws WC_Data_Exception |
||
615 | */ |
||
616 | public function set_exclude_sale_items( $exclude_sale_items ) { |
||
619 | |||
620 | /** |
||
621 | * Set the minimum spend amount. |
||
622 | * @since 2.7.0 |
||
623 | * @param float $amount |
||
624 | * @throws WC_Data_Exception |
||
625 | */ |
||
626 | public function set_minimum_amount( $amount ) { |
||
629 | |||
630 | /** |
||
631 | * Set the maximum spend amount. |
||
632 | * @since 2.7.0 |
||
633 | * @param float $amount |
||
634 | * @throws WC_Data_Exception |
||
635 | */ |
||
636 | public function set_maximum_amount( $amount ) { |
||
639 | |||
640 | /** |
||
641 | * Set email restrictions. |
||
642 | * @since 2.7.0 |
||
643 | * @param array $emails |
||
644 | * @throws WC_Data_Exception |
||
645 | */ |
||
646 | public function set_email_restrictions( $emails = array() ) { |
||
655 | |||
656 | /** |
||
657 | * Set which users have used this coupon. |
||
658 | * @since 2.7.0 |
||
659 | * @param array $used_by |
||
660 | * @throws WC_Data_Exception |
||
661 | */ |
||
662 | public function set_used_by( $used_by ) { |
||
665 | |||
666 | /* |
||
667 | |-------------------------------------------------------------------------- |
||
668 | | CRUD methods |
||
669 | |-------------------------------------------------------------------------- |
||
670 | | |
||
671 | | Methods which create, read, update and delete coupons from the database. |
||
672 | | |
||
673 | | A save method is included for convenience (chooses update or create based |
||
674 | | on if the order exists yet). |
||
675 | | |
||
676 | */ |
||
677 | |||
678 | /** |
||
679 | * Reads an coupon from the database and sets its data to the class. |
||
680 | * @since 2.7.0 |
||
681 | * @param int $coupon_id |
||
682 | */ |
||
683 | public function read( $coupon_id ) { |
||
725 | |||
726 | /** |
||
727 | * Create a new coupon. |
||
728 | * @since 2.7.0 |
||
729 | */ |
||
730 | public function create() { |
||
751 | |||
752 | /** |
||
753 | * Updates an existing coupon. |
||
754 | * @since 2.7.0 |
||
755 | */ |
||
756 | public function update() { |
||
770 | |||
771 | /** |
||
772 | * Save data (either create or update depending on if we are working on an existing coupon) |
||
773 | * @since 2.7.0 |
||
774 | */ |
||
775 | public function save() { |
||
782 | |||
783 | /** |
||
784 | * Delete coupon from the database. |
||
785 | * @since 2.7.0 |
||
786 | */ |
||
787 | public function delete() { |
||
791 | |||
792 | /** |
||
793 | * Helper method that updates all the post meta for a coupon based on it's settings in the WC_Coupon class. |
||
794 | * @since 2.7.0 |
||
795 | * @param int $coupon_id |
||
796 | */ |
||
797 | private function update_post_meta( $coupon_id ) { |
||
816 | |||
817 | /** |
||
818 | * Developers can programically return coupons. This function will read those values into our WC_Coupon class. |
||
819 | * @since 2.7.0 |
||
820 | * @param string $code Coupon code |
||
821 | * @param array $coupon Array of coupon properties |
||
822 | */ |
||
823 | public function read_manual_coupon( $code, $coupon ) { |
||
853 | |||
854 | /* |
||
855 | |-------------------------------------------------------------------------- |
||
856 | | Other Actions |
||
857 | |-------------------------------------------------------------------------- |
||
858 | */ |
||
859 | |||
860 | /** |
||
861 | * Increase usage count for current coupon. |
||
862 | * |
||
863 | * @param string $used_by Either user ID or billing email |
||
864 | */ |
||
865 | public function inc_usage_count( $used_by = '' ) { |
||
875 | |||
876 | /** |
||
877 | * Decrease usage count for current coupon. |
||
878 | * |
||
879 | * @param string $used_by Either user ID or billing email |
||
880 | */ |
||
881 | public function dcr_usage_count( $used_by = '' ) { |
||
899 | |||
900 | /* |
||
901 | |-------------------------------------------------------------------------- |
||
902 | | Validation & Error Handling |
||
903 | |-------------------------------------------------------------------------- |
||
904 | */ |
||
905 | |||
906 | /** |
||
907 | * Returns the error_message string. |
||
908 | * |
||
909 | * @access public |
||
910 | * @return string |
||
911 | */ |
||
912 | public function get_error_message() { |
||
915 | |||
916 | /** |
||
917 | * Ensure coupon exists or throw exception. |
||
918 | * |
||
919 | * @throws Exception |
||
920 | */ |
||
921 | private function validate_exists() { |
||
926 | |||
927 | /** |
||
928 | * Ensure coupon usage limit is valid or throw exception. |
||
929 | * |
||
930 | * @throws Exception |
||
931 | */ |
||
932 | private function validate_usage_limit() { |
||
937 | |||
938 | /** |
||
939 | * Ensure coupon user usage limit is valid or throw exception. |
||
940 | * |
||
941 | * Per user usage limit - check here if user is logged in (against user IDs). |
||
942 | * Checked again for emails later on in WC_Cart::check_customer_coupons(). |
||
943 | * |
||
944 | * @param int $user_id |
||
945 | * @throws Exception |
||
946 | */ |
||
947 | private function validate_user_usage_limit( $user_id = 0 ) { |
||
960 | |||
961 | /** |
||
962 | * Ensure coupon date is valid or throw exception. |
||
963 | * |
||
964 | * @throws Exception |
||
965 | */ |
||
966 | private function validate_expiry_date() { |
||
971 | |||
972 | /** |
||
973 | * Ensure coupon amount is valid or throw exception. |
||
974 | * |
||
975 | * @throws Exception |
||
976 | */ |
||
977 | private function validate_minimum_amount() { |
||
982 | |||
983 | /** |
||
984 | * Ensure coupon amount is valid or throw exception. |
||
985 | * |
||
986 | * @throws Exception |
||
987 | */ |
||
988 | private function validate_maximum_amount() { |
||
993 | |||
994 | /** |
||
995 | * Ensure coupon is valid for products in the cart is valid or throw exception. |
||
996 | * |
||
997 | * @throws Exception |
||
998 | */ |
||
999 | View Code Duplication | private function validate_product_ids() { |
|
1014 | |||
1015 | /** |
||
1016 | * Ensure coupon is valid for product categories in the cart is valid or throw exception. |
||
1017 | * |
||
1018 | * @throws Exception |
||
1019 | */ |
||
1020 | View Code Duplication | private function validate_product_categories() { |
|
1038 | |||
1039 | /** |
||
1040 | * Ensure coupon is valid for sale items in the cart is valid or throw exception. |
||
1041 | * |
||
1042 | * @throws Exception |
||
1043 | */ |
||
1044 | View Code Duplication | private function validate_sale_items() { |
|
1065 | |||
1066 | /** |
||
1067 | * All exclusion rules must pass at the same time for a product coupon to be valid. |
||
1068 | */ |
||
1069 | private function validate_excluded_items() { |
||
1085 | |||
1086 | /** |
||
1087 | * Cart discounts cannot be added if non-eligble product is found in cart. |
||
1088 | */ |
||
1089 | private function validate_cart_excluded_items() { |
||
1096 | |||
1097 | /** |
||
1098 | * Exclude products from cart. |
||
1099 | * |
||
1100 | * @throws Exception |
||
1101 | */ |
||
1102 | View Code Duplication | private function validate_cart_excluded_product_ids() { |
|
1118 | |||
1119 | /** |
||
1120 | * Exclude categories from cart. |
||
1121 | * |
||
1122 | * @throws Exception |
||
1123 | */ |
||
1124 | View Code Duplication | private function validate_cart_excluded_product_categories() { |
|
1140 | |||
1141 | /** |
||
1142 | * Exclude sale items from cart. |
||
1143 | * |
||
1144 | * @throws Exception |
||
1145 | */ |
||
1146 | View Code Duplication | private function validate_cart_excluded_sale_items() { |
|
1166 | |||
1167 | /** |
||
1168 | * Check if a coupon is valid. |
||
1169 | * |
||
1170 | * @return boolean validity |
||
1171 | * @throws Exception |
||
1172 | */ |
||
1173 | public function is_valid() { |
||
1197 | |||
1198 | /** |
||
1199 | * Check if a coupon is valid. |
||
1200 | * |
||
1201 | * @return bool |
||
1202 | */ |
||
1203 | public function is_valid_for_cart() { |
||
1206 | |||
1207 | /** |
||
1208 | * Check if a coupon is valid for a product. |
||
1209 | * |
||
1210 | * @param WC_Product $product |
||
1211 | * @return boolean |
||
1212 | */ |
||
1213 | public function is_valid_for_product( $product, $values = array() ) { |
||
1262 | |||
1263 | /** |
||
1264 | * Converts one of the WC_Coupon message/error codes to a message string and. |
||
1265 | * displays the message/error. |
||
1266 | * |
||
1267 | * @param int $msg_code Message/error code. |
||
1268 | */ |
||
1269 | public function add_coupon_message( $msg_code ) { |
||
1282 | |||
1283 | /** |
||
1284 | * Map one of the WC_Coupon message codes to a message string. |
||
1285 | * |
||
1286 | * @param integer $msg_code |
||
1287 | * @return string| Message/error string |
||
1288 | */ |
||
1289 | View Code Duplication | public function get_coupon_message( $msg_code ) { |
|
1303 | |||
1304 | /** |
||
1305 | * Map one of the WC_Coupon error codes to a message string. |
||
1306 | * |
||
1307 | * @param int $err_code Message/error code. |
||
1308 | * @return string| Message/error string |
||
1309 | */ |
||
1310 | public function get_coupon_error( $err_code ) { |
||
1386 | |||
1387 | /** |
||
1388 | * Map one of the WC_Coupon error codes to an error string. |
||
1389 | * No coupon instance will be available where a coupon does not exist, |
||
1390 | * so this static method exists. |
||
1391 | * |
||
1392 | * @param int $err_code Error code |
||
1393 | * @return string| Error string |
||
1394 | */ |
||
1395 | View Code Duplication | public static function get_generic_coupon_error( $err_code ) { |
|
1410 | } |
||
1411 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: