MC4WP_EDD_Integration

The MailChimp for WordPress Lite MC4WP EDD Integration class.

Defined (1)

The class is defined in the following location(s).

/includes/integrations/class-edd.php  
  1. class MC4WP_EDD_Integration extends MC4WP_Integration { 
  2.  
  3. /** 
  4. * @var string 
  5. */ 
  6. protected $type = 'edd_checkout'; 
  7.  
  8. /** 
  9. * Constructor 
  10. */ 
  11. public function __construct() { 
  12.  
  13. parent::__construct(); 
  14.  
  15. add_action( 'edd_purchase_form_user_info_fields', array( $this, 'output_checkbox' ) ); 
  16. add_action( 'edd_payment_meta', array( $this, 'save_checkbox_value' ) ); 
  17. add_action( 'edd_complete_purchase', array( $this, 'subscribe_from_edd'), 50 ); 
  18.  
  19. /** 
  20. * @param array $meta 
  21. * @return array 
  22. */ 
  23. public function save_checkbox_value( $meta ) { 
  24.  
  25. // don't save anything if the checkbox was not checked 
  26. if( ! $this->checkbox_was_checked() ) { 
  27. return $meta; 
  28.  
  29. $meta['_mc4wp_optin'] = 1; 
  30. return $meta; 
  31.  
  32. /** 
  33. * @param int $payment_id The ID of the payment 
  34. * @return bool|string 
  35. */ 
  36. public function subscribe_from_edd( $payment_id ) { 
  37.  
  38. $meta = edd_get_payment_meta( $payment_id ); 
  39.  
  40. if( ! is_array( $meta ) || ! isset( $meta['_mc4wp_optin'] ) || ! $meta['_mc4wp_optin'] ) { 
  41. return false; 
  42.  
  43. $email = (string) edd_get_payment_user_email( $payment_id ); 
  44. $merge_vars = array(); 
  45.  
  46. // add first and last name to merge vars, if given 
  47. $user_info = (array) edd_get_payment_meta_user_info( $payment_id ); 
  48.  
  49. if( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) { 
  50. $merge_vars['NAME'] = $user_info['first_name'] . ' ' . $user_info['last_name']; 
  51.  
  52. if( isset( $user_info['first_name'] ) ) { 
  53. $merge_vars['FNAME'] = $user_info['first_name']; 
  54.  
  55. if( isset( $user_info['last_name'] ) ) { 
  56. $merge_vars['LNAME'] = $user_info['last_name']; 
  57.  
  58.  
  59.  
  60. return $this->subscribe( $email, $merge_vars, $this->type, $payment_id ); 
  61.