diff --git a/includes/class-ckwc-integration.php b/includes/class-ckwc-integration.php index dd944b1..afbd0d9 100644 --- a/includes/class-ckwc-integration.php +++ b/includes/class-ckwc-integration.php @@ -443,7 +443,7 @@ public function init_form_fields() { $this->form_fields = array( // Account name. - 'account_name' => array( + 'account_name' => array( 'title' => __( 'Account Name', 'woocommerce-convertkit' ), 'type' => 'oauth_disconnect', 'label' => __( 'Disconnect', 'woocommerce-convertkit' ), @@ -462,7 +462,7 @@ public function init_form_fields() { ), // Enable/Disable entire integration. - 'enabled' => array( + 'enabled' => array( 'title' => __( 'Enable/Disable', 'woocommerce-convertkit' ), 'type' => 'checkbox', 'label' => __( 'Enable ConvertKit integration', 'woocommerce-convertkit' ), @@ -470,7 +470,7 @@ public function init_form_fields() { ), // Subscribe. - 'event' => array( + 'event' => array( 'title' => __( 'Subscribe Event', 'woocommerce-convertkit' ), 'type' => 'select', 'default' => 'pending', @@ -508,7 +508,7 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe', ), - 'subscription' => array( + 'subscription' => array( 'title' => __( 'Subscription', 'woocommerce-convertkit' ), 'type' => 'subscription', 'default' => '', @@ -517,7 +517,7 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe', ), - 'name_format' => array( + 'name_format' => array( 'title' => __( 'Name Format', 'woocommerce-convertkit' ), 'type' => 'select', 'default' => 'first', @@ -534,7 +534,7 @@ public function init_form_fields() { ), // Custom Field Mappings. - 'custom_field_last_name' => array( + 'custom_field_last_name' => array( 'title' => __( 'Send Last Name', 'woocommerce-convertkit' ), 'type' => 'custom_field', 'default' => '', @@ -543,7 +543,7 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe', ), - 'custom_field_phone' => array( + 'custom_field_phone' => array( 'title' => __( 'Send Phone Number', 'woocommerce-convertkit' ), 'type' => 'custom_field', 'default' => '', @@ -552,7 +552,7 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe', ), - 'custom_field_billing_address' => array( + 'custom_field_billing_address' => array( 'title' => __( 'Send Billing Address', 'woocommerce-convertkit' ), 'type' => 'custom_field', 'default' => '', @@ -561,7 +561,7 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe', ), - 'custom_field_shipping_address' => array( + 'custom_field_shipping_address' => array( 'title' => __( 'Send Shipping Address', 'woocommerce-convertkit' ), 'type' => 'custom_field', 'default' => '', @@ -570,7 +570,16 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe', ), - 'custom_field_payment_method' => array( + 'custom_field_address_exclude_name' => array( + 'title' => __( 'Exclude Name from Billing & Shipping Addresses', 'woocommerce-convertkit' ), + 'type' => 'checkbox', + 'default' => 'no', + 'description' => __( 'If enabled, removes the order\'s first name, last name and company name when storing the billing and shipping address above.', 'woocommerce-convertkit' ), + + // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. + 'class' => 'enabled subscribe', + ), + 'custom_field_payment_method' => array( 'title' => __( 'Send Payment Method', 'woocommerce-convertkit' ), 'type' => 'custom_field', 'default' => '', @@ -579,7 +588,7 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe', ), - 'custom_field_customer_note' => array( + 'custom_field_customer_note' => array( 'title' => __( 'Send Customer Note', 'woocommerce-convertkit' ), 'type' => 'custom_field', 'default' => '', @@ -590,7 +599,7 @@ public function init_form_fields() { ), // Subscribe: Display Opt In Checkbox Settings. - 'display_opt_in' => array( + 'display_opt_in' => array( 'title' => __( 'Opt-In Checkbox', 'woocommerce-convertkit' ), 'label' => __( 'Display an opt-in checkbox on checkout', 'woocommerce-convertkit' ), 'type' => 'checkbox', @@ -605,7 +614,7 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe', ), - 'opt_in_label' => array( + 'opt_in_label' => array( 'title' => __( 'Opt-In Checkbox: Label', 'woocommerce-convertkit' ), 'type' => 'text', 'default' => __( 'I want to subscribe to the newsletter', 'woocommerce-convertkit' ), @@ -615,7 +624,7 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe display_opt_in', ), - 'opt_in_status' => array( + 'opt_in_status' => array( 'title' => __( 'Opt-In Checkbox: Default Status', 'woocommerce-convertkit' ), 'type' => 'select', 'default' => 'checked', @@ -629,7 +638,7 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe display_opt_in', ), - 'opt_in_location' => array( + 'opt_in_location' => array( 'title' => __( 'Opt-In Checkbox: Display Location', 'woocommerce-convertkit' ), 'type' => 'select', 'default' => 'billing', @@ -645,7 +654,7 @@ public function init_form_fields() { ), // Purchase Data. - 'send_purchases' => array( + 'send_purchases' => array( 'title' => __( 'Purchase Data', 'woocommerce-convertkit' ), 'label' => __( 'Send purchase data to ConvertKit.', 'woocommerce-convertkit' ), 'type' => 'checkbox', @@ -660,7 +669,7 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe', ), - 'send_purchases_event' => array( + 'send_purchases_event' => array( 'title' => __( 'Purchase Data Event', 'woocommerce-convertkit' ), 'type' => 'select', 'default' => 'processing', @@ -691,7 +700,7 @@ public function init_form_fields() { // The setting name that needs to be checked/enabled for this setting to display. Used by JS to toggle visibility. 'class' => 'enabled subscribe send_purchases', ), - 'sync_past_orders' => array( + 'sync_past_orders' => array( 'title' => __( 'Sync Past Orders', 'woocommerce-convertkit' ), 'label' => __( 'Send old purchase data to ConvertKit i.e. Orders that were created in WooCommerce prior to this Plugin being installed.', 'woocommerce-convertkit' ), 'type' => 'sync_past_orders_button', @@ -708,7 +717,7 @@ public function init_form_fields() { ), // Debugging. - 'debug' => array( + 'debug' => array( 'title' => __( 'Debug', 'woocommerce-convertkit' ), 'type' => 'checkbox', 'label' => __( 'Write data to a log file', 'woocommerce-convertkit' ), diff --git a/includes/class-ckwc-order.php b/includes/class-ckwc-order.php index 7b4667f..c5af17e 100644 --- a/includes/class-ckwc-order.php +++ b/includes/class-ckwc-order.php @@ -966,6 +966,14 @@ private function custom_field_data( $order ) { $fields = array(); + // If the name and company name should be excluded from the billing and shipping address + // fetched using get_formatted_billing_address() / get_formatted_shipping_address(), + // add filters now. + if ( $this->integration->get_option_bool( 'custom_field_address_exclude_name' ) ) { + add_filter( 'woocommerce_order_formatted_billing_address', array( $this, 'remove_name_from_address' ) ); + add_filter( 'woocommerce_order_formatted_shipping_address', array( $this, 'remove_name_from_address' ) ); + } + if ( $this->integration->get_option( 'custom_field_last_name' ) ) { $fields[ $this->integration->get_option( 'custom_field_last_name' ) ] = $order->get_billing_last_name(); } @@ -985,6 +993,14 @@ private function custom_field_data( $order ) { $fields[ $this->integration->get_option( 'custom_field_customer_note' ) ] = $order->get_customer_note(); } + // If the name and company name should be excluded from the billing and shipping address + // fetched using get_formatted_billing_address() / get_formatted_shipping_address(), + // remove filters now so these WooCommerce functions work correctly for other Plugins. + if ( $this->integration->get_option_bool( 'custom_field_address_exclude_name' ) ) { + remove_filter( 'woocommerce_order_formatted_billing_address', array( $this, 'remove_name_from_address' ) ); + remove_filter( 'woocommerce_order_formatted_shipping_address', array( $this, 'remove_name_from_address' ) ); + } + /** * Returns an array of ConvertKit Custom Field Key/Value pairs, with values * comprising of Order data based, to be sent to ConvertKit when an Order's @@ -1003,4 +1019,20 @@ private function custom_field_data( $order ) { } + /** + * Removes the first name, last name and company name from the WooCommerce Order address, + * when calling WC_Order->get_formatted_billing_address() and WC_Order->get_formatted_shipping_address(). + * + * @since 1.8.5 + * + * @param array $address Billing or Shipping Address. + * @return array + */ + public function remove_name_from_address( $address ) { + + unset( $address['first_name'], $address['last_name'], $address['company_name'] ); + return $address; + + } + } diff --git a/tests/_support/Helper/Acceptance/ConvertKitAPI.php b/tests/_support/Helper/Acceptance/ConvertKitAPI.php index 0b2fac1..2f63811 100644 --- a/tests/_support/Helper/Acceptance/ConvertKitAPI.php +++ b/tests/_support/Helper/Acceptance/ConvertKitAPI.php @@ -215,14 +215,15 @@ public function apiUnsubscribe($id) /** * Check the subscriber array's custom field data is valid. * - * @param AcceptanceTester $I AcceptanceTester. - * @param array $subscriber Subscriber from API. + * @param AcceptanceTester $I AcceptanceTester. + * @param array $subscriber Subscriber from API. + * @param bool $excludeNameFromAddress Exclude name from billing address. */ - public function apiCustomFieldDataIsValid($I, $subscriber) + public function apiCustomFieldDataIsValid($I, $subscriber, $excludeNameFromAddress = false) { $I->assertEquals($subscriber['fields']['last_name'], 'Last'); $I->assertEquals($subscriber['fields']['phone_number'], '123-123-1234'); - $I->assertEquals($subscriber['fields']['billing_address'], 'First Last, Address Line 1, City, CA 12345'); + $I->assertEquals($subscriber['fields']['billing_address'], ( $excludeNameFromAddress ? 'Address Line 1, City, CA 12345' : 'First Last, Address Line 1, City, CA 12345' )); $I->assertEquals($subscriber['fields']['payment_method'], 'cod'); $I->assertEquals($subscriber['fields']['notes'], 'Notes'); } diff --git a/tests/_support/Helper/Acceptance/Plugin.php b/tests/_support/Helper/Acceptance/Plugin.php index c4a641f..537af9c 100644 --- a/tests/_support/Helper/Acceptance/Plugin.php +++ b/tests/_support/Helper/Acceptance/Plugin.php @@ -85,15 +85,16 @@ public function deactivateWooCommerceAndConvertKitPlugins($I) * * @since 1.6.0 * - * @param AcceptanceTester $I Acceptance Tester. - * @param bool|string $accessToken Access Token (if specified, used instead of CONVERTKIT_OAUTH_ACCESS_TOKEN). - * @param bool|string $refreshToken Refresh Token (if specified, used instead of CONVERTKIT_OAUTH_REFRESH_TOKEN). - * @param string $subscriptionEvent Subscribe Event. - * @param bool|string $subscription Form, Tag or Sequence to subscribe customer to. - * @param string $nameFormat Name Format. - * @param bool $mapCustomFields Map Order data to Custom Fields. - * @param bool $displayOptIn Display Opt-In Checkbox. - * @param bool $sendPurchaseDataEvent Send Purchase Data to ConvertKit on Order Event. + * @param AcceptanceTester $I Acceptance Tester. + * @param bool|string $accessToken Access Token (if specified, used instead of CONVERTKIT_OAUTH_ACCESS_TOKEN). + * @param bool|string $refreshToken Refresh Token (if specified, used instead of CONVERTKIT_OAUTH_REFRESH_TOKEN). + * @param string $subscriptionEvent Subscribe Event. + * @param bool|string $subscription Form, Tag or Sequence to subscribe customer to. + * @param string $nameFormat Name Format. + * @param bool $mapCustomFields Map Order data to Custom Fields. + * @param bool $displayOptIn Display Opt-In Checkbox. + * @param bool $sendPurchaseDataEvent Send Purchase Data to ConvertKit on Order Event. + * @param bool $excludeNameFromAddress Exclude name from billing and shipping addresses. */ public function setupConvertKitPlugin( $I, @@ -104,39 +105,41 @@ public function setupConvertKitPlugin( $nameFormat = 'first', $mapCustomFields = false, $displayOptIn = false, - $sendPurchaseDataEvent = false + $sendPurchaseDataEvent = false, + $excludeNameFromAddress = false ) { // Define Plugin's settings. $I->haveOptionInDatabase( 'woocommerce_ckwc_settings', [ - 'enabled' => 'yes', - 'access_token' => ( $accessToken !== false ? $accessToken : $_ENV['CONVERTKIT_OAUTH_ACCESS_TOKEN'] ), - 'refresh_token' => ( $refreshToken !== false ? $refreshToken : $_ENV['CONVERTKIT_OAUTH_REFRESH_TOKEN'] ), - 'event' => $subscriptionEvent, - 'subscription' => ( $subscription ? $subscription : '' ), - 'name_format' => $nameFormat, + 'enabled' => 'yes', + 'access_token' => ( $accessToken !== false ? $accessToken : $_ENV['CONVERTKIT_OAUTH_ACCESS_TOKEN'] ), + 'refresh_token' => ( $refreshToken !== false ? $refreshToken : $_ENV['CONVERTKIT_OAUTH_REFRESH_TOKEN'] ), + 'event' => $subscriptionEvent, + 'subscription' => ( $subscription ? $subscription : '' ), + 'name_format' => $nameFormat, // Custom Field mappings. - 'custom_field_last_name' => ( $mapCustomFields ? 'last_name' : '' ), - 'custom_field_phone' => ( $mapCustomFields ? 'phone_number' : '' ), - 'custom_field_billing_address' => ( $mapCustomFields ? 'billing_address' : '' ), - 'custom_field_shipping_address' => ( $mapCustomFields ? 'shipping_address' : '' ), - 'custom_field_payment_method' => ( $mapCustomFields ? 'payment_method' : '' ), - 'custom_field_customer_note' => ( $mapCustomFields ? 'notes' : '' ), + 'custom_field_last_name' => ( $mapCustomFields ? 'last_name' : '' ), + 'custom_field_phone' => ( $mapCustomFields ? 'phone_number' : '' ), + 'custom_field_billing_address' => ( $mapCustomFields ? 'billing_address' : '' ), + 'custom_field_shipping_address' => ( $mapCustomFields ? 'shipping_address' : '' ), + 'custom_field_payment_method' => ( $mapCustomFields ? 'payment_method' : '' ), + 'custom_field_customer_note' => ( $mapCustomFields ? 'notes' : '' ), + 'custom_field_address_exclude_name' => ( $excludeNameFromAddress ? 'yes' : 'no' ), // Opt-In Checkbox. - 'display_opt_in' => ( $displayOptIn ? 'yes' : 'no' ), - 'opt_in_label' => 'I want to subscribe to the newsletter', - 'opt_in_status' => 'checked', - 'opt_in_location' => 'billing', + 'display_opt_in' => ( $displayOptIn ? 'yes' : 'no' ), + 'opt_in_label' => 'I want to subscribe to the newsletter', + 'opt_in_status' => 'checked', + 'opt_in_location' => 'billing', // Purchase Data. - 'send_purchases' => ( $sendPurchaseDataEvent ? 'yes' : 'no' ), - 'send_purchases_event' => ( $sendPurchaseDataEvent ? $sendPurchaseDataEvent : '' ), + 'send_purchases' => ( $sendPurchaseDataEvent ? 'yes' : 'no' ), + 'send_purchases_event' => ( $sendPurchaseDataEvent ? $sendPurchaseDataEvent : '' ), // Debug. - 'debug' => 'yes', + 'debug' => 'yes', ] ); } diff --git a/tests/_support/Helper/Acceptance/WooCommerce.php b/tests/_support/Helper/Acceptance/WooCommerce.php index 3d85bc9..83fc2b2 100644 --- a/tests/_support/Helper/Acceptance/WooCommerce.php +++ b/tests/_support/Helper/Acceptance/WooCommerce.php @@ -210,6 +210,7 @@ public function wooCommerceCreateProductAndCheckoutWithConfig($I, $options = fal 'send_purchase_data' => false, 'product_form_tag_sequence' => false, 'custom_fields' => false, + 'exclude_name_from_address' => false, 'name_format' => 'first', 'coupon_form_tag_sequence' => false, 'use_legacy_checkout' => true, @@ -232,7 +233,8 @@ public function wooCommerceCreateProductAndCheckoutWithConfig($I, $options = fal $options['name_format'], $options['custom_fields'], $options['display_opt_in'], - ( ( $options['send_purchase_data'] === true ) ? 'processing' : $options['send_purchase_data'] ) + ( ( $options['send_purchase_data'] === true ) ? 'processing' : $options['send_purchase_data'] ), + $options['exclude_name_from_address'] ); // Create Product. diff --git a/tests/acceptance/purchase-data/PurchaseDataCest.php b/tests/acceptance/purchase-data/PurchaseDataCest.php index 8375299..d0475ce 100644 --- a/tests/acceptance/purchase-data/PurchaseDataCest.php +++ b/tests/acceptance/purchase-data/PurchaseDataCest.php @@ -76,7 +76,7 @@ public function testSendPurchaseDataWithSimpleProductCheckout(AcceptanceTester $ } /** - * Test that the Customer's purchase is sent to ConvertKit when: + * Test that the Customer's purchase is sent to ConvertKit with custom field data when: * - The 'Send purchase data to ConvertKit' is enabled in the integration Settings, and * - The opt in settings are disabled, and * - The Customer purchases a 'Simple' WooCommerce Product, and @@ -122,6 +122,56 @@ public function testSendPurchaseDataWithCustomFieldsOnSimpleProductCheckout(Acce $I->apiUnsubscribe($subscriber['id']); } + /** + * Test that the Customer's purchase is sent to ConvertKit with custom field data when: + * - The 'Send purchase data to ConvertKit' is enabled in the integration Settings, and + * - The opt in settings are disabled, and + * - The Customer purchases a 'Simple' WooCommerce Product, and + * - The Order is created via the frontend checkout. + * - The Address Custom Fields in ConvertKit do not include the name + * + * @since 1.8.5 + * + * @param AcceptanceTester $I Tester. + */ + public function testSendPurchaseDataWithCustomFieldsAndExcludeNameFromAddressOnSimpleProductCheckout(AcceptanceTester $I) + { + // Create Product and Checkout for this test. + $result = $I->wooCommerceCreateProductAndCheckoutWithConfig( + $I, + [ + 'display_opt_in' => false, + 'check_opt_in' => false, + 'send_purchase_data' => true, + 'custom_fields' => true, + 'exclude_name_from_address' => true, + ] + ); + + // Confirm that the purchase was added to ConvertKit. + $purchaseDataID = $I->apiCheckPurchaseExists($I, $result['order_id'], $result['email_address'], $result['product_id']); + + // Check that the Order's Notes include a note from the Plugin confirming the purchase was added to ConvertKit. + $I->wooCommerceOrderNoteExists($I, $result['order_id'], '[ConvertKit] Purchase Data sent successfully: ID [' . $purchaseDataID . ']'); + + // Confirm that the Transaction ID is stored in the Order's metadata. + $I->wooCommerceOrderMetaKeyAndValueExist($I, $result['order_id'], 'ckwc_purchase_data_sent', 'yes', true); + $I->wooCommerceOrderMetaKeyAndValueExist($I, $result['order_id'], 'ckwc_purchase_data_id', $purchaseDataID, true); + + // Confirm that the email address was now added to ConvertKit. + $subscriber = $I->apiCheckSubscriberExists($I, $result['email_address'], 'First'); + + // Confirm the subscriber's custom field data exists and is correct, and the name + // is not included in the address. + $I->apiCustomFieldDataIsValid($I, $subscriber, true); + + // Check that the Order's Notes include a note from the Plugin confirming the custom field data was added to ConvertKit. + $I->wooCommerceOrderNoteExists($I, $result['order_id'], '[ConvertKit] Purchase Data: Custom Fields sent successfully: Subscriber ID [' . $subscriber['id'] . ']'); + + // Unsubscribe the email address, so we restore the account back to its previous state. + $I->apiUnsubscribe($subscriber['id']); + } + /** * Test that the Customer's purchase is not sent to ConvertKit when: * - The 'Send purchase data to ConvertKit' is disabled in the integration Settings, and diff --git a/tests/acceptance/settings/SettingCustomFieldsCest.php b/tests/acceptance/settings/SettingCustomFieldsCest.php index 1406988..20c9deb 100644 --- a/tests/acceptance/settings/SettingCustomFieldsCest.php +++ b/tests/acceptance/settings/SettingCustomFieldsCest.php @@ -53,6 +53,7 @@ public function testCustomFields(AcceptanceTester $I) $I->selectOption('#woocommerce_ckwc_custom_field_phone', 'Phone Number'); $I->selectOption('#woocommerce_ckwc_custom_field_billing_address', 'Billing Address'); $I->selectOption('#woocommerce_ckwc_custom_field_shipping_address', 'Shipping Address'); + $I->checkOption('#woocommerce_ckwc_custom_field_address_exclude_name'); $I->selectOption('#woocommerce_ckwc_custom_field_payment_method', 'Payment Method'); $I->selectOption('#woocommerce_ckwc_custom_field_customer_note', 'Notes'); @@ -67,6 +68,7 @@ public function testCustomFields(AcceptanceTester $I) $I->seeOptionIsSelected('#woocommerce_ckwc_custom_field_phone', 'Phone Number'); $I->seeOptionIsSelected('#woocommerce_ckwc_custom_field_billing_address', 'Billing Address'); $I->seeOptionIsSelected('#woocommerce_ckwc_custom_field_shipping_address', 'Shipping Address'); + $I->seeCheckboxIsChecked('#woocommerce_ckwc_custom_field_address_exclude_name'); $I->seeOptionIsSelected('#woocommerce_ckwc_custom_field_payment_method', 'Payment Method'); $I->seeOptionIsSelected('#woocommerce_ckwc_custom_field_customer_note', 'Notes'); } diff --git a/tests/acceptance/subscribe/SubscribeCheckoutBlockOnOrderProcessingEventCest.php b/tests/acceptance/subscribe/SubscribeCheckoutBlockOnOrderProcessingEventCest.php index 0c68eba..cfeecfa 100644 --- a/tests/acceptance/subscribe/SubscribeCheckoutBlockOnOrderProcessingEventCest.php +++ b/tests/acceptance/subscribe/SubscribeCheckoutBlockOnOrderProcessingEventCest.php @@ -173,6 +173,46 @@ public function testOptInWhenCheckedWithFormCustomFieldsAndSimpleProduct(Accepta $I->apiUnsubscribe($subscriber['id']); } + /** + * Test that the Customer is subscribed to ConvertKit when: + * - The opt in checkbox is enabled in the integration Settings, and + * - Order data is mapped to ConvertKit Custom fields in the integration Settings, and + * - The opt in checkbox is checked on the WooCommerce checkout, and + * - The Customer purchases a 'Simple' WooCommerce Product, and + * - The Customer is subscribed at the point the WooCommerce Order is marked as processing. + * - The Customer's name is not included in the address custom field. + * + * @since 1.8.5 + * + * @param AcceptanceTester $I Tester. + */ + public function testOptInWhenCheckedWithFormCustomFieldsAndExcludeNameFromAddressOnSimpleProduct(AcceptanceTester $I) + { + // Create Product and Checkout for this test. + $result = $I->wooCommerceCreateProductAndCheckoutWithConfig( + $I, + [ + 'display_opt_in' => true, + 'check_opt_in' => true, + 'plugin_form_tag_sequence' => 'form:' . $_ENV['CONVERTKIT_API_FORM_ID'], + 'subscription_event' => 'processing', + 'custom_fields' => true, + 'exclude_name_from_address' => true, + 'use_legacy_checkout' => false, + ] + ); + + // Confirm that the email address was now added to ConvertKit. + $subscriber = $I->apiCheckSubscriberExists($I, $result['email_address'], 'First'); + + // Confirm the subscriber's custom field data exists and is correct, and the name + // is not included in the address. + $I->apiCustomFieldDataIsValid($I, $subscriber, true); + + // Unsubscribe the email address, so we restore the account back to its previous state. + $I->apiUnsubscribe($subscriber['id']); + } + /** * Test that the Customer is subscribed to ConvertKit when: * - The opt in checkbox is enabled in the integration Settings, and diff --git a/tests/acceptance/subscribe/SubscribeOnOrderCompletedEventCest.php b/tests/acceptance/subscribe/SubscribeOnOrderCompletedEventCest.php index 2259a6e..8dd3fd3 100644 --- a/tests/acceptance/subscribe/SubscribeOnOrderCompletedEventCest.php +++ b/tests/acceptance/subscribe/SubscribeOnOrderCompletedEventCest.php @@ -242,6 +242,51 @@ public function testOptInWhenCheckedWithFormCustomFieldsAndSimpleProduct(Accepta $I->apiUnsubscribe($subscriber['id']); } + /** + * Test that the Customer is subscribed to ConvertKit when: + * - The opt in checkbox is enabled in the integration Settings, and + * - Order data is mapped to ConvertKit Custom fields in the integration Settings, and + * - The opt in checkbox is checked on the WooCommerce checkout, and + * - The Customer purchases a 'Simple' WooCommerce Product, and + * - The Customer is subscribed at the point the WooCommerce Order is marked as completed. + * - The Customer's name is not included in the address custom field. + * + * @since 1.8.5 + * + * @param AcceptanceTester $I Tester. + */ + public function testOptInWhenCheckedWithFormCustomFieldsAndExcludeNameFromAddressOnSimpleProduct(AcceptanceTester $I) + { + // Create Product and Checkout for this test. + $result = $I->wooCommerceCreateProductAndCheckoutWithConfig( + $I, + [ + 'display_opt_in' => true, + 'check_opt_in' => true, + 'plugin_form_tag_sequence' => 'form:' . $_ENV['CONVERTKIT_API_FORM_ID'], + 'subscription_event' => 'completed', + 'custom_fields' => true, + 'exclude_name_from_address' => true, + ] + ); + + // Confirm that the email address wasn't yet added to ConvertKit. + $I->apiCheckSubscriberDoesNotExist($I, $result['email_address']); + + // Change the Order status = Completed, to trigger the Order Completed event. + $I->wooCommerceChangeOrderStatus($I, $result['order_id'], 'wc-completed'); + + // Confirm that the email address was now added to ConvertKit. + $subscriber = $I->apiCheckSubscriberExists($I, $result['email_address'], 'First'); + + // Confirm the subscriber's custom field data exists and is correct, and the name + // is not included in the address. + $I->apiCustomFieldDataIsValid($I, $subscriber, true); + + // Unsubscribe the email address, so we restore the account back to its previous state. + $I->apiUnsubscribe($subscriber['id']); + } + /** * Test that the Customer is subscribed to ConvertKit when: * - The opt in checkbox is enabled in the integration Settings, and diff --git a/tests/acceptance/subscribe/SubscribeOnOrderPendingPaymentEventCest.php b/tests/acceptance/subscribe/SubscribeOnOrderPendingPaymentEventCest.php index 10ca6a3..a599636 100644 --- a/tests/acceptance/subscribe/SubscribeOnOrderPendingPaymentEventCest.php +++ b/tests/acceptance/subscribe/SubscribeOnOrderPendingPaymentEventCest.php @@ -151,6 +151,45 @@ public function testOptInWhenCheckedWithFormCustomFieldsAndSimpleProduct(Accepta $I->apiUnsubscribe($subscriber['id']); } + /** + * Test that the Customer is subscribed to ConvertKit when: + * - The opt in checkbox is enabled in the integration Settings, and + * - Order data is mapped to ConvertKit Custom fields in the integration Settings, and + * - The opt in checkbox is checked on the WooCommerce checkout, and + * - The Customer purchases a 'Simple' WooCommerce Product, and + * - The Customer is subscribed at the point the WooCommerce Order is marked as processing. + * - The Customer's name is not included in the address custom field. + * + * @since 1.8.5 + * + * @param AcceptanceTester $I Tester. + */ + public function testOptInWhenCheckedWithFormCustomFieldsAndExcludeNameFromAddressOnSimpleProduct(AcceptanceTester $I) + { + // Create Product and Checkout for this test. + $result = $I->wooCommerceCreateProductAndCheckoutWithConfig( + $I, + [ + 'display_opt_in' => true, + 'check_opt_in' => true, + 'plugin_form_tag_sequence' => 'form:' . $_ENV['CONVERTKIT_API_FORM_ID'], + 'subscription_event' => 'pending', + 'custom_fields' => true, + 'exclude_name_from_address' => true, + ] + ); + + // Confirm that the email address was now added to ConvertKit. + $subscriber = $I->apiCheckSubscriberExists($I, $result['email_address'], 'First'); + + // Confirm the subscriber's custom field data exists and is correct, and the name + // is not included in the address. + $I->apiCustomFieldDataIsValid($I, $subscriber, true); + + // Unsubscribe the email address, so we restore the account back to its previous state. + $I->apiUnsubscribe($subscriber['id']); + } + /** * Test that the Customer is subscribed to ConvertKit when: * - The opt in checkbox is enabled in the integration Settings, and diff --git a/tests/acceptance/subscribe/SubscribeOnOrderProcessingEventCest.php b/tests/acceptance/subscribe/SubscribeOnOrderProcessingEventCest.php index 861df26..4c034f2 100644 --- a/tests/acceptance/subscribe/SubscribeOnOrderProcessingEventCest.php +++ b/tests/acceptance/subscribe/SubscribeOnOrderProcessingEventCest.php @@ -169,6 +169,45 @@ public function testOptInWhenCheckedWithFormCustomFieldsAndSimpleProduct(Accepta $I->apiUnsubscribe($subscriber['id']); } + /** + * Test that the Customer is subscribed to ConvertKit when: + * - The opt in checkbox is enabled in the integration Settings, and + * - Order data is mapped to ConvertKit Custom fields in the integration Settings, and + * - The opt in checkbox is checked on the WooCommerce checkout, and + * - The Customer purchases a 'Simple' WooCommerce Product, and + * - The Customer is subscribed at the point the WooCommerce Order is marked as processing. + * - The Customer's name is not included in the address custom field. + * + * @since 1.8.5 + * + * @param AcceptanceTester $I Tester. + */ + public function testOptInWhenCheckedWithFormCustomFieldsAndExcludeNameFromAddressOnSimpleProduct(AcceptanceTester $I) + { + // Create Product and Checkout for this test. + $result = $I->wooCommerceCreateProductAndCheckoutWithConfig( + $I, + [ + 'display_opt_in' => true, + 'check_opt_in' => true, + 'plugin_form_tag_sequence' => 'form:' . $_ENV['CONVERTKIT_API_FORM_ID'], + 'subscription_event' => 'processing', + 'custom_fields' => true, + 'exclude_name_from_address' => true, + ] + ); + + // Confirm that the email address was now added to ConvertKit. + $subscriber = $I->apiCheckSubscriberExists($I, $result['email_address'], 'First'); + + // Confirm the subscriber's custom field data exists and is correct, and the name + // is not included in the address. + $I->apiCustomFieldDataIsValid($I, $subscriber, true); + + // Unsubscribe the email address, so we restore the account back to its previous state. + $I->apiUnsubscribe($subscriber['id']); + } + /** * Test that the Customer is subscribed to ConvertKit when: * - The opt in checkbox is enabled in the integration Settings, and