Skip to content

Commit

Permalink
Merge pull request #189 from ConvertKit/set-subscriber-state-inactive…
Browse files Browse the repository at this point in the history
…-forms

Create subscriber with `inactive` state when a Form option is selected
  • Loading branch information
n7studios authored Aug 15, 2024
2 parents 22dbc60 + e9f5290 commit fa927a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions includes/class-ckwc-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,23 @@ public function subscribe_customer( $resource_type, $resource_id, $email, $name,
// Call API to subscribe the email address to the given Form, Tag or Sequence.
switch ( $resource_type ) {
case 'form':
// Subscribe with inactive state.
$subscriber = $this->api->create_subscriber( $email, $name, 'inactive', $custom_fields );

// If an error occured, don't attempt to add the subscriber to the Form, as it won't work.
if ( is_wp_error( $subscriber ) ) {
return;
}

// For Legacy Forms, a different endpoint is used.
$forms = new CKWC_Resource_Forms();
if ( $forms->is_legacy( $resource_id ) ) {
$result = $this->api->legacy_form_subscribe( $resource_id, $email, $name, $custom_fields );
$result = $this->api->add_subscriber_to_legacy_form( $resource_id, $subscriber['subscriber']['id'] );
break;
}

$result = $this->api->form_subscribe( $resource_id, $email, $name, $custom_fields );
// Add subscriber to form.
$result = $this->api->add_subscriber_to_form( $resource_id, $subscriber['subscriber']['id'] );
break;

case 'tag':
Expand Down
3 changes: 3 additions & 0 deletions tests/_support/Helper/Acceptance/ConvertKitAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public function apiCheckSubscriberExists($I, $emailAddress, $firstName = false)
[
'email_address' => $emailAddress,
'include_total_count' => true,

// Check all subscriber states.
'status' => 'all',
]
);

Expand Down

0 comments on commit fa927a7

Please sign in to comment.