Skip to content

Commit 99e61b5

Browse files
committed
merge in CC-34 to our 1.1.0 release
1 parent 5a58db1 commit 99e61b5

File tree

3 files changed

+101
-8
lines changed

3 files changed

+101
-8
lines changed

README.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ and send targeted emails that engage your customers on every device.
2020

2121
Unleash the power of your business—and drive more revenue—by integrating Constant Contact with WooCommerce today.
2222

23-
== Changelog ==
24-
25-
= 1.1.0 =
26-
27-
* Added: Campaign ID data inclusion for purchased orders originating from your mailing campaigns.
28-
* Fixed: compatibility issue with phone numbers and PHP 7.3
29-
* Updated: Wording in our WooCommerce tab.
30-
3123
With Constant Contact you can:
3224
- Drag and drop products from your store into any email and customize the details.
3325
- Automatically import WooCommere contacts into your Constant Contact account.
@@ -40,3 +32,11 @@ With Constant Contact you can:
4032
--- Prospects: Have not made a purchase yet
4133
- Send automated welcome emails and behavior based trigger emails
4234
- Find new customers with Facebook and Instagram ads
35+
36+
== Changelog ==
37+
38+
= 1.1.0 =
39+
40+
* Added: Campaign ID data inclusion for purchased orders originating from your mailing campaigns.
41+
* Fixed: compatibility issue with phone numbers and PHP 7.3
42+
* Updated: Wording in our WooCommerce tab.

src/View/Checkout/CampaignId.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Class to handle filtering fields in the checkout billing form.
4+
*
5+
* @see https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
6+
* @author Michael Beckwith <[email protected]>
7+
* @package WebDevStudios\CCForWoo\View\Checkout
8+
* @since 2019-08-22
9+
*/
10+
11+
namespace WebDevStudios\CCForWoo\View\Checkout;
12+
13+
use WebDevStudios\OopsWP\Utility\Hookable;
14+
15+
/**
16+
* Class CampaignId
17+
*
18+
* @author Michael Beckwith <[email protected]>
19+
* @package WebDevStudios\CCForWoo\View\Checkout
20+
* @since 2019-08-22
21+
*/
22+
class CampaignId implements Hookable {
23+
/**
24+
* The name of the meta field for the customer's preference.
25+
* This constant will be used both in usermeta (for users) and postmeta (for orders).
26+
*
27+
* @var string
28+
* @since 2019-08-22
29+
*/
30+
const CUSTOMER_CAMPAIGN_ID_KEY = 'campaign_activity_id';
31+
32+
/**
33+
* Register actions and filters with WordPress.
34+
*
35+
* @author Michael Beckwith <[email protected]>
36+
* @since 2019-08-22
37+
*/
38+
public function register_hooks() {
39+
add_action( 'init', [ $this, 'save_campaign_id' ], 11 );
40+
add_action( 'woocommerce_checkout_update_order_meta', [ $this, 'save_user_campaign_id_to_order' ] );
41+
}
42+
43+
/**
44+
* Save the user preference to the order meta.
45+
*
46+
* @param int $order_id The order ID.
47+
*
48+
* @author Michael Beckwith <[email protected]>
49+
* @since 2019-08-22
50+
* @return void
51+
*/
52+
public function save_user_campaign_id_to_order( $order_id ) {
53+
$preference = $this->get_stored_campaign_id();
54+
55+
if ( empty( $preference ) ) {
56+
return;
57+
}
58+
59+
add_post_meta( $order_id, self::CUSTOMER_CAMPAIGN_ID_KEY, $preference, true );
60+
}
61+
62+
/**
63+
* Save the campaign ID for the session.
64+
*
65+
* @throws \Exception DateTime exception.
66+
*
67+
* @author Michael Beckwith <[email protected]>
68+
* @since 2019-08-22
69+
* @return void
70+
*/
71+
public function save_campaign_id() {
72+
$campaign_id = filter_input( INPUT_GET, 'source', FILTER_SANITIZE_STRING );
73+
74+
if ( ! empty( $campaign_id ) ) {
75+
setcookie( 'ctct_woo_campaign_id', $campaign_id, 0, '/' );
76+
}
77+
}
78+
79+
/**
80+
* Get the submitted customer newsletter preference.
81+
*
82+
* @author Michael Beckwith <[email protected]>
83+
* @since 2019-08-22
84+
* @return string
85+
*/
86+
private function get_stored_campaign_id() {
87+
return isset( $_COOKIE['ctct_woo_campaign_id'] )
88+
? sanitize_text_field( $_COOKIE['ctct_woo_campaign_id'] )
89+
: '';
90+
}
91+
}

src/View/ViewRegistrar.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace WebDevStudios\CCForWoo\View;
1111

1212
use WebDevStudios\CCForWoo\View\Admin\WooTab;
13+
use WebDevStudios\CCForWoo\View\Checkout\CampaignId;
1314
use WebDevStudios\CCForWoo\View\Checkout\NewsletterPreferenceCheckbox;
1415
use WebDevStudios\OopsWP\Structure\Service;
1516

@@ -35,6 +36,7 @@ class ViewRegistrar extends Service {
3536
*/
3637
protected $forms = [
3738
NewsletterPreferenceCheckbox::class,
39+
CampaignId::class,
3840
];
3941

4042

0 commit comments

Comments
 (0)