暫無描述

class-wc-coupon-tracking.php 1.1KB

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