class-wc-admin-setup-wizard-tracking.php
5 years ago
class-wc-coupon-tracking.php
6 years ago
class-wc-coupons-tracking.php
6 years ago
class-wc-extensions-tracking.php
6 years ago
class-wc-importer-tracking.php
6 years ago
class-wc-order-tracking.php
6 years ago
class-wc-orders-tracking.php
5 years ago
class-wc-products-tracking.php
6 years ago
class-wc-settings-tracking.php
5 years ago
class-wc-status-tracking.php
6 years ago
class-wc-coupon-tracking.php
40 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Coupon Tracking |
| 4 | * |
| 5 | * @package WooCommerce\Tracks |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * This class adds actions to track usage of a WooCommerce Coupon. |
| 10 | */ |
| 11 | class WC_Coupon_Tracking { |
| 12 | |
| 13 | /** |
| 14 | * Init tracking. |
| 15 | */ |
| 16 | public function init() { |
| 17 | add_action( 'woocommerce_coupon_object_updated_props', array( $this, 'track_coupon_updated' ), 10, 2 ); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Send a Tracks event when a coupon is updated. |
| 22 | * |
| 23 | * @param WC_Coupon $coupon The coupon that has been updated. |
| 24 | * @param Array $updated_props The props of the coupon that have been updated. |
| 25 | */ |
| 26 | public function track_coupon_updated( $coupon, $updated_props ) { |
| 27 | $properties = array( |
| 28 | 'discount_code' => $coupon->get_code(), |
| 29 | 'free_shipping' => $coupon->get_free_shipping(), |
| 30 | 'individual_use' => $coupon->get_individual_use(), |
| 31 | 'exclude_sale_items' => $coupon->get_exclude_sale_items(), |
| 32 | 'usage_limits_applied' => 0 < intval( $coupon->get_usage_limit() ) |
| 33 | || 0 < intval( $coupon->get_usage_limit_per_user() ) |
| 34 | || 0 < intval( $coupon->get_limit_usage_to_x_items() ), |
| 35 | ); |
| 36 | |
| 37 | WC_Tracks::record_event( 'coupon_updated', $properties ); |
| 38 | } |
| 39 | } |
| 40 |