Pixel Manager for WooCommerce – Track Google Analytics, Google Ads, Facebook and more - Version 1.1

Version Description

Download this release

Release Info

Developer alekv
Plugin Icon 128x128 Pixel Manager for WooCommerce – Track Google Analytics, Google Ads, Facebook and more
Version 1.1
Comparing to
See all releases

Code changes from version 1.0.6 to 1.1

Files changed (2) hide show
  1. readme.txt +8 -5
  2. wgact.php +144 -159
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: alekv
3
  Donate link: http://www.wolfundbaer.ch/donations/
4
  Tags: WooCommerce, Google AdWords, AdWords, conversion, conversion value, conversion tag, conversion value tracking, conversion tracking
5
  Requires at least: 3.1
6
- Tested up to: 4.4
7
- Stable tag: 1.0.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -24,13 +24,13 @@ Thanks to Adrijana Nikolic from http://webhostinggeeks.com for the translation i
24
 
25
  == Installation ==
26
 
27
- 1. Upload the wgact plugin directory into your `/wp-content/plugins/` directory
28
  2. Activate the plugin through the 'Plugins' menu in WordPress
29
  3. Get the AdWords conversion ID and the conversion label. You will find both values in the AdWords conversion tracking code.
30
- 4. In the WordpPress admin panel go to settings and then into the WGACT Plugin Menu. Please enter the conversion ID and the conversion label into their respective fields.
31
  5. Delete any other instances of the AdWords tracking code which tracks sales. (You might have several AdWords tracking codes, eg. tracking newsletter applications. Keep those.)
32
  6. Delete the cache on your server and on your browser.
33
- 7. Check if the AdWords tag is running fine by placing a test order (ideally click on one of your AdWords ads first) and then check with the Google Tag Assistang browser plugin if the tag has been inserted corretly on the thank you page.
34
 
35
  == Frequently Asked Questions ==
36
 
@@ -47,6 +47,9 @@ You can send the link to the front page of your shop too if you think it would b
47
 
48
  == Changelog ==
49
 
 
 
 
50
  = 1.0.6 =
51
  * Tweak: Switching single pixel function from transient to post meta
52
  = 1.0.5 =
3
  Donate link: http://www.wolfundbaer.ch/donations/
4
  Tags: WooCommerce, Google AdWords, AdWords, conversion, conversion value, conversion tag, conversion value tracking, conversion tracking
5
  Requires at least: 3.1
6
+ Tested up to: 4.4.2
7
+ Stable tag: 1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
24
 
25
  == Installation ==
26
 
27
+ 1. Upload the WGACT Plugin directory into your `/wp-content/plugins/` directory
28
  2. Activate the plugin through the 'Plugins' menu in WordPress
29
  3. Get the AdWords conversion ID and the conversion label. You will find both values in the AdWords conversion tracking code.
30
+ 4. In the WordPress admin panel go to settings and then into the WGACT Plugin Menu. Please enter the conversion ID and the conversion label into their respective fields.
31
  5. Delete any other instances of the AdWords tracking code which tracks sales. (You might have several AdWords tracking codes, eg. tracking newsletter applications. Keep those.)
32
  6. Delete the cache on your server and on your browser.
33
+ 7. Check if the AdWords tag is running fine by placing a test order (ideally click on one of your AdWords ads first) and then check with the Google Tag Assistant browser plugin if the tag has been inserted correctly on the thank you page. Bear in mind that the code is only visible if you are not logged in as admin or shop manager. You will have to log out first.
34
 
35
  == Frequently Asked Questions ==
36
 
47
 
48
  == Changelog ==
49
 
50
+ = 1.0.7 =
51
+ * Tweak: Code cleanup
52
+ * Tweak: To avoid over reporting only insert the retargeting code for visitors, not shop managers and admins
53
  = 1.0.6 =
54
  * Tweak: Switching single pixel function from transient to post meta
55
  = 1.0.5 =
wgact.php CHANGED
@@ -1,156 +1,153 @@
1
  <?php
2
  /**
3
- Plugin Name: WooCommerce AdWords Conversion Tracking
4
- Plugin URI: https://wordpress.org/plugins/woocommerce-google-adwords-conversion-tracking-tag/
5
- Description: Google AdWords dynamic conversion value tracking for WooCommerce.
6
- Author: Wolf + Bär GmbH
7
- Author URI: http://www.wolfundbaer.ch
8
- Version: 1.0.6
9
- License: GPLv2 or later
10
- Text Domain: woocommerce-google-adwords-conversion-tracking-tag
11
- **/
12
-
13
- // Security measure: http://mikejolley.com/2013/08/keeping-your-shit-secure-whilst-developing-for-wordpress/
14
  if ( ! defined( 'ABSPATH' ) ) {
15
  exit; // Exit if accessed directly
16
  }
17
 
18
 
19
- class WGACT{
20
-
21
- public function __construct(){
22
- /*
23
- // check if WooCommerce is installed. CHECK DISABLED because it doesn't work properly when the multisite feature is turned on in WP
24
- if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
25
-
26
- // insert the tracking code into the footer of the WooCommerce page
27
-
28
- // using the woo_foot hook leads to problems with some themes. using wp_footer instead should solve it for all themes, as long as they use the standard wp_footer hook
29
- add_action( 'woo_foot', array( $this, 'GoogleAdWordsTag' ));
30
- add_action( 'wp_footer', array( $this, 'GoogleAdWordsTag' ));
31
- }
32
- */
33
-
34
- /**
35
- You might ask yourself why I am inserting the following function.
36
- A bit more information on that: Unfortunately there is a filter in WordPress (up to the current version 3.8.1) which messes up the Google AdWords tracking tag after injecting it into the thankyou page. The following function will fix this and is only a workaround until WordPress releases a fix. Accolaeds to awezlzel who posted this workaround. This bug was reported years ago and is still an open issue: http://core.trac.wordpress.org/ticket/3670
37
- **/
38
-
39
- function cdata_markupfix($content) { $content = str_replace("]]&gt;", "]]>", $content); return $content; }
40
- function cdata_template_redirect( $content ) { ob_start('cdata_markupfix'); }
41
- //add_action('template_redirect','cdata_template_redirect',-1);
42
-
43
- // add the Google AdWords tag to the footer of the page
44
- //add_action( 'wp_head', array( $this, 'GoogleAdWordsTag' ));
45
-
46
- // add the Google AdWords tag to the thankyou part of the page within the body tags
47
- add_action( 'woocommerce_thankyou', array( $this, 'GoogleAdWordsTag' ));
48
-
49
  // add the admin options page
50
- // add_action('admin_menu', array( $this, 'wgact_plugin_admin_add_page'));
51
- add_action('admin_menu', array( $this, 'wgact_plugin_admin_add_page'),99);
52
-
53
  // install a settings page in the admin console
54
- add_action('admin_init', array( $this, 'wgact_plugin_admin_init'));
55
-
56
  // add a settings link on the plugins page
57
- add_filter('plugin_action_links', array($this, 'wgact_settings_link'), 10, 2);
58
-
59
  // Load textdomain
60
- // source: http://wordpress.stackexchange.com/questions/80334/how-to-make-a-wordpress-plugin-translation-ready
61
- // source: http://fooplugins.com/make-a-wordpress-plugin-translations/
62
- // source: http://geertdedeckere.be/article/loading-wordpress-language-files-the-right-way
63
- add_action('init', array($this, 'load_plugin_textdomain'));
64
 
65
-
66
  }
67
-
 
 
 
 
 
 
 
 
 
 
 
68
  // Load text domain function
69
- public function load_plugin_textdomain(){
70
- load_plugin_textdomain('woocommerce-google-adwords-conversion-tracking-tag', FALSE, dirname(plugin_basename(__FILE__)).'/languages/');
71
  }
72
-
73
  // adds a link on the plugins page for the wgact settings
74
- function wgact_settings_link($links, $file) {
75
- if ($file == plugin_basename(__FILE__))
76
- $links[] = '<a href="' . admin_url("admin.php?page=do_wgact") . '">'. __('Settings') .'</a>';
 
 
77
  return $links;
78
  }
79
-
80
  // add the admin options page
81
  function wgact_plugin_admin_add_page() {
82
  //add_options_page('WGACT Plugin Page', 'WGACT Plugin Menu', 'manage_options', 'do_wgact', array($this, 'wgact_plugin_options_page'));
83
- add_submenu_page('woocommerce', esc_html__( 'AdWords Conversion Tracking', 'woocommerce-google-adwords-conversion-tracking-tag' ), esc_html__( 'AdWords Conversion Tracking', 'woocommerce-google-adwords-conversion-tracking-tag' ), 'manage_options', 'do_wgact', array($this, 'wgact_plugin_options_page'));
 
 
 
84
  }
85
 
86
  // display the admin options page
87
  function wgact_plugin_options_page() {
88
-
89
- // Throw a warning if WooCommerce is disabled. CHECK DISABLED because it doesn't work properly when the multisite feature is turned on in WP
90
- /*
91
- if (! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
92
- echo '<div><h1><font color="red"><b>WooCommerce not active -> tag insertion disabled !</b></font></h1></div>';
93
- }
94
- */
95
-
96
  ?>
97
 
98
- <br>
99
- <div style="background: #eee; width: 772px">
100
- <div style="background: #ccc; padding: 10px; font-weight: bold"><?php esc_html_e( 'AdWords Conversion Tracking Settings', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?></div>
101
- <form action="options.php" method="post">
102
-
103
- <?php settings_fields('wgact_plugin_options'); ?>
104
- <?php do_settings_sections('do_wgact'); ?>
105
  <br>
106
- <table class="form-table" style="margin: 10px">
107
- <tr>
108
- <th scope="row" style="white-space: nowrap">
109
- <input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" class="button" />
110
- </th>
111
-
112
- </tr>
113
- </table>
114
- </form>
115
-
 
 
 
 
 
 
116
  </div>
117
-
118
  <br>
119
-
120
  <div style="background: #eee; width: 772px">
121
  <div style="background: #ccc; padding: 10px; font-weight: bold"><?php esc_html_e( 'Donation', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?></div>
122
-
123
- <table class="form-table" style="margin: 10px">
124
- <tr>
125
- <th scope="row">
126
- <div style="padding: 10px"><?php esc_html_e( 'This plugin was developed by', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?> <a href="http://www.wolfundbaer.ch" target="_blank">Wolf + Bär GmbH</a><p><?php esc_html_e( 'Buy me a beer if you like the plugin.', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?><br>
127
- <?php esc_html_e( 'If you want me to continue developing the plugin buy me a few more beers. Although, I probably will continue to develop the plugin anyway. It would be just much more fun if I had a few beers to celebrate my milestones.', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?></div>
128
-
129
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
130
- <input type="hidden" name="cmd" value="_s-xclick">
131
- <input type="hidden" name="hosted_button_id" value="UE3D2AW8YTML8">
132
- <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
133
- <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
134
- </form>
135
- </th>
136
- </tr>
137
- </table>
 
 
 
 
 
138
  </div>
139
 
140
  <?php
141
-
142
-
143
  }
144
 
145
 
146
  // add the admin settings and such
147
- function wgact_plugin_admin_init(){
148
- //register_setting( 'plugin_options', 'plugin_options', 'wgact_plugin_options_validate' );
149
- register_setting( 'wgact_plugin_options', 'wgact_plugin_options_1');
150
- register_setting( 'wgact_plugin_options', 'wgact_plugin_options_2');
151
- add_settings_section('wgact_plugin_main', esc_html__( 'Main Settings', 'woocommerce-google-adwords-conversion-tracking-tag' ), array($this,'wgact_plugin_section_text'), 'do_wgact');
152
- add_settings_field('wgact_plugin_text_string_1', esc_html__( 'Conversion ID', 'woocommerce-google-adwords-conversion-tracking-tag' ), array($this,'wgact_plugin_setting_string_1'), 'do_wgact', 'wgact_plugin_main');
153
- add_settings_field('wgact_plugin_text_string_2', esc_html__( 'Conversion Label', 'woocommerce-google-adwords-conversion-tracking-tag' ), array($this,'wgact_plugin_setting_string_2'), 'do_wgact', 'wgact_plugin_main');
 
 
 
 
 
 
 
 
 
154
  }
155
 
156
  function wgact_plugin_section_text() {
@@ -165,12 +162,12 @@ A bit more information on that: Unfortunately there is a filter in WordPress (up
165
  */
166
 
167
  function wgact_plugin_setting_string_1() {
168
- $options = get_option('wgact_plugin_options_1');
169
- echo "<input id='wgact_plugin_text_string_1' name='wgact_plugin_options_1[text_string]' size='40' type='text' value='{$options['text_string']}' />";
170
  }
171
 
172
  function wgact_plugin_setting_string_2() {
173
- $options = get_option('wgact_plugin_options_2');
174
  echo "<input id='wgact_plugin_text_string_2' name='wgact_plugin_options_2[text_string]' size='40' type='text' value='{$options['text_string']}' />";
175
  }
176
 
@@ -182,71 +179,59 @@ A bit more information on that: Unfortunately there is a filter in WordPress (up
182
  */
183
 
184
  // validate our options
185
- function wgact_plugin_options_validate($input) {
186
- $newinput['text_string'] = trim($input['text_string']);
187
- if(!preg_match('/^[a-z0-9]{32}$/i', $newinput['text_string'])) {
188
  $newinput['text_string'] = '';
189
  }
 
190
  return $newinput;
191
  }
192
-
193
- private function get_conversion_id(){
194
- $opt = get_option('wgact_plugin_options_1');
195
  $conversion_id = $opt['text_string'];
 
196
  return $conversion_id;
197
  }
198
 
199
- private function get_conversion_label(){
200
- $opt = get_option('wgact_plugin_options_2');
201
  $conversion_label = $opt['text_string'];
 
202
  return $conversion_label;
203
  }
204
 
205
- private function get_mc_prefix(){
206
- $opt = get_option('wgact_plugin_options_3');
207
- $mc_prefix = $opt['text_string'];
208
- return $mc_prefix;
209
- }
210
-
211
  // insert the Google AdWords tag into the page
212
- public function GoogleAdWordsTag($order_id) {
213
 
214
  $conversion_id = $this->get_conversion_id();
215
  $conversion_label = $this->get_conversion_label();
216
- $mc_prefix = $this->get_mc_prefix();
217
-
218
  // get order from URL and evaluate order total
219
- $order = new WC_Order( $order_id );
220
  $order_total = $order->get_total();
221
-
222
  // Only run conversion script if the payment has not failed. (has_status('completed') is too restrictive)
223
  // And use the order meta to check if the conversion code has already run for this order ID. If yes, don't run it again.
224
- // Unfortunately the WC session gets destroyed for not logged in users which is why I solved this with a transient and left the WC session code for testing purposes.
225
- // source: https://docs.woothemes.com/wc-apidocs/class-WC_Session.html
226
- // source: http://stackoverflow.com/questions/27199656/how-to-use-session-in-woocommerce-pages-like-we-use-normal-php-session
227
- // WC()->session->set_customer_session_cookie(true); // Try to reactivate WC session to keep session state
228
- // if ( !$order->has_status( 'failed' ) && ((WC()->session->get( 'single_conversion_identifier' ) != $order_id))){
229
- // if ( !$order->has_status( 'failed' ) && ((get_transient( 'wgact_transient_ID_' . $order_id ) != $order_id))){
230
- if ( !$order->has_status( 'failed' ) && ((get_post_meta( $order_id, '_WGACT_conversion_pixel_fired' , true) != "true"))){
231
- ?>
232
-
233
- <!-- START Google Code for Sales (AdWords) Conversion Page -->
234
-
235
- <div style="display:inline;">
236
- <img height="1" width="1" style="border-style:none;" alt="" src="http<?php if(is_ssl()){echo "s";}?>://www.googleadservices.com/pagead/conversion/<?php echo $conversion_id; ?>/?value=<?php echo $order_total; ?>&amp;currency_code=<?php echo $order->get_order_currency(); ?>&amp;label=<?php echo $conversion_label; ?>&amp;guid=ON&amp;script=0"/>
237
- </div>
238
-
239
- <!-- END Google Code for Sales (AdWords) Conversion Page -->
240
-
241
- <?php
242
  // Set the order ID meta after the conversion code has run once.
243
- // WC()->session->set( 'single_conversion_identifier' , $order_id );
244
- //set_transient( 'wgact_transient_ID_' . $order_id, $order_id, 60*60*12 );
245
  update_post_meta( $order_id, '_WGACT_conversion_pixel_fired', 'true' );
246
  } // end if order status
247
  }
248
  }
249
 
250
- $wgact = new WGACT();
251
-
252
- ?>
1
  <?php
2
  /**
3
+ * Plugin Name: WooCommerce AdWords Conversion Tracking
4
+ * Plugin URI: https://wordpress.org/plugins/woocommerce-google-adwords-conversion-tracking-tag/
5
+ * Description: Google AdWords dynamic conversion value tracking for WooCommerce.
6
+ * Author: Wolf+Bär GmbH
7
+ * Author URI: https://wolfundbaer.ch
8
+ * Version: 1.1
9
+ * License: GPLv2 or later
10
+ * Text Domain: woocommerce-google-adwords-conversion-tracking-tag
11
+ **/
12
+
 
13
  if ( ! defined( 'ABSPATH' ) ) {
14
  exit; // Exit if accessed directly
15
  }
16
 
17
 
18
+ class WGACT {
19
+
20
+ public function __construct() {
21
+
22
+ // startup all functions
23
+ $this->init();
24
+
25
+ }
26
+
27
+ // startup all functions
28
+ public function init() {
29
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  // add the admin options page
31
+ add_action( 'admin_menu', array( $this, 'wgact_plugin_admin_add_page' ), 99 );
32
+
 
33
  // install a settings page in the admin console
34
+ add_action( 'admin_init', array( $this, 'wgact_plugin_admin_init' ) );
35
+
36
  // add a settings link on the plugins page
37
+ add_filter( 'plugin_action_links', array( $this, 'wgact_settings_link' ), 10, 2 );
38
+
39
  // Load textdomain
40
+ add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
41
+
42
+ // insert the conversion code only for visitors of the site
43
+ add_action( 'plugins_loaded', array( $this, 'run_conversion_pixel_for_visitor' ) );
44
 
 
45
  }
46
+
47
+ // only run the conversion code for visitors, not for the admin or shop managers
48
+ public function run_conversion_pixel_for_visitor() {
49
+
50
+ // don't load the pixel if a shop manager oder the admin is logged in
51
+ if ( ! current_user_can( 'edit_others_pages' ) ) {
52
+
53
+ // add the Google AdWords tag to the thankyou part of the page within the body tags
54
+ add_action( 'woocommerce_thankyou', array( $this, 'GoogleAdWordsTag' ) );
55
+ }
56
+ }
57
+
58
  // Load text domain function
59
+ public function load_plugin_textdomain() {
60
+ load_plugin_textdomain( 'woocommerce-google-adwords-conversion-tracking-tag', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
61
  }
62
+
63
  // adds a link on the plugins page for the wgact settings
64
+ function wgact_settings_link( $links, $file ) {
65
+ if ( $file == plugin_basename( __FILE__ ) ) {
66
+ $links[] = '<a href="' . admin_url( "admin.php?page=do_wgact" ) . '">' . __( 'Settings' ) . '</a>';
67
+ }
68
+
69
  return $links;
70
  }
71
+
72
  // add the admin options page
73
  function wgact_plugin_admin_add_page() {
74
  //add_options_page('WGACT Plugin Page', 'WGACT Plugin Menu', 'manage_options', 'do_wgact', array($this, 'wgact_plugin_options_page'));
75
+ add_submenu_page( 'woocommerce', esc_html__( 'AdWords Conversion Tracking', 'woocommerce-google-adwords-conversion-tracking-tag' ), esc_html__( 'AdWords Conversion Tracking', 'woocommerce-google-adwords-conversion-tracking-tag' ), 'manage_options', 'do_wgact', array(
76
+ $this,
77
+ 'wgact_plugin_options_page'
78
+ ) );
79
  }
80
 
81
  // display the admin options page
82
  function wgact_plugin_options_page() {
83
+
 
 
 
 
 
 
 
84
  ?>
85
 
 
 
 
 
 
 
 
86
  <br>
87
+ <div style="background: #eee; width: 772px">
88
+ <div
89
+ style="background: #ccc; padding: 10px; font-weight: bold"><?php esc_html_e( 'AdWords Conversion Tracking Settings', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?></div>
90
+ <form action="options.php" method="post">
91
+ <?php settings_fields( 'wgact_plugin_options' ); ?>
92
+ <?php do_settings_sections( 'do_wgact' ); ?>
93
+ <br>
94
+ <table class="form-table" style="margin: 10px">
95
+ <tr>
96
+ <th scope="row" style="white-space: nowrap">
97
+ <input name="Submit" type="submit" value="<?php esc_attr_e( 'Save Changes' ); ?>"
98
+ class="button"/>
99
+ </th>
100
+ </tr>
101
+ </table>
102
+ </form>
103
  </div>
 
104
  <br>
 
105
  <div style="background: #eee; width: 772px">
106
  <div style="background: #ccc; padding: 10px; font-weight: bold"><?php esc_html_e( 'Donation', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?></div>
107
+ <table class="form-table" style="margin: 10px">
108
+ <tr>
109
+ <th scope="row">
110
+ <div
111
+ style="padding: 10px"><?php esc_html_e( 'This plugin was developed by', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?>
112
+ <a href="http://www.wolfundbaer.ch" target="_blank">Wolf + Bär GmbH</a>
113
+ <p><?php esc_html_e( 'Buy me a beer if you like the plugin.', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?>
114
+ <br>
115
+ <?php esc_html_e( 'If you want me to continue developing the plugin buy me a few more beers. Although, I probably will continue to develop the plugin anyway. It would be just much more fun if I had a few beers to celebrate my milestones.', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?>
116
+ </div>
117
+ <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
118
+ <input type="hidden" name="cmd" value="_s-xclick">
119
+ <input type="hidden" name="hosted_button_id" value="UE3D2AW8YTML8">
120
+ <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif"
121
+ name="submit" alt="PayPal - The safer, easier way to pay online!">
122
+ <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1"
123
+ height="1">
124
+ </form>
125
+ </th>
126
+ </tr>
127
+ </table>
128
  </div>
129
 
130
  <?php
 
 
131
  }
132
 
133
 
134
  // add the admin settings and such
135
+ function wgact_plugin_admin_init() {
136
+ //register_setting( 'plugin_options', 'plugin_options', 'wgact_plugin_options_validate' );
137
+ register_setting( 'wgact_plugin_options', 'wgact_plugin_options_1' );
138
+ register_setting( 'wgact_plugin_options', 'wgact_plugin_options_2' );
139
+ add_settings_section( 'wgact_plugin_main', esc_html__( 'Main Settings', 'woocommerce-google-adwords-conversion-tracking-tag' ), array(
140
+ $this,
141
+ 'wgact_plugin_section_text'
142
+ ), 'do_wgact' );
143
+ add_settings_field( 'wgact_plugin_text_string_1', esc_html__( 'Conversion ID', 'woocommerce-google-adwords-conversion-tracking-tag' ), array(
144
+ $this,
145
+ 'wgact_plugin_setting_string_1'
146
+ ), 'do_wgact', 'wgact_plugin_main' );
147
+ add_settings_field( 'wgact_plugin_text_string_2', esc_html__( 'Conversion Label', 'woocommerce-google-adwords-conversion-tracking-tag' ), array(
148
+ $this,
149
+ 'wgact_plugin_setting_string_2'
150
+ ), 'do_wgact', 'wgact_plugin_main' );
151
  }
152
 
153
  function wgact_plugin_section_text() {
162
  */
163
 
164
  function wgact_plugin_setting_string_1() {
165
+ $options = get_option( 'wgact_plugin_options_1' );
166
+ echo "<input id='wgact_plugin_text_string_1' name='wgact_plugin_options_1[text_string]' size='40' type='text' value='{$options['text_string']}' />";
167
  }
168
 
169
  function wgact_plugin_setting_string_2() {
170
+ $options = get_option( 'wgact_plugin_options_2' );
171
  echo "<input id='wgact_plugin_text_string_2' name='wgact_plugin_options_2[text_string]' size='40' type='text' value='{$options['text_string']}' />";
172
  }
173
 
179
  */
180
 
181
  // validate our options
182
+ function wgact_plugin_options_validate( $input ) {
183
+ $newinput['text_string'] = trim( $input['text_string'] );
184
+ if ( ! preg_match( '/^[a-z0-9]{32}$/i', $newinput['text_string'] ) ) {
185
  $newinput['text_string'] = '';
186
  }
187
+
188
  return $newinput;
189
  }
190
+
191
+ private function get_conversion_id() {
192
+ $opt = get_option( 'wgact_plugin_options_1' );
193
  $conversion_id = $opt['text_string'];
194
+
195
  return $conversion_id;
196
  }
197
 
198
+ private function get_conversion_label() {
199
+ $opt = get_option( 'wgact_plugin_options_2' );
200
  $conversion_label = $opt['text_string'];
201
+
202
  return $conversion_label;
203
  }
204
 
 
 
 
 
 
 
205
  // insert the Google AdWords tag into the page
206
+ public function GoogleAdWordsTag( $order_id ) {
207
 
208
  $conversion_id = $this->get_conversion_id();
209
  $conversion_label = $this->get_conversion_label();
210
+
 
211
  // get order from URL and evaluate order total
212
+ $order = new WC_Order( $order_id );
213
  $order_total = $order->get_total();
214
+
215
  // Only run conversion script if the payment has not failed. (has_status('completed') is too restrictive)
216
  // And use the order meta to check if the conversion code has already run for this order ID. If yes, don't run it again.
217
+ if ( ! $order->has_status( 'failed' ) && ( ( get_post_meta( $order_id, '_WGACT_conversion_pixel_fired', true ) != "true" ) ) ) {
218
+ ?>
219
+
220
+ <!-- START Google Code for Sales (AdWords) Conversion Page -->
221
+
222
+ <div style="display:inline;">
223
+ <img height="1" width="1" style="border-style:none;" alt="" src="http<?php if ( is_ssl() ) {
224
+ echo "s";
225
+ } ?>://www.googleadservices.com/pagead/conversion/<?php echo $conversion_id; ?>/?value=<?php echo $order_total; ?>&amp;currency_code=<?php echo $order->get_order_currency(); ?>&amp;label=<?php echo $conversion_label; ?>&amp;guid=ON&amp;script=0"/>
226
+ </div>
227
+
228
+ <!-- END Google Code for Sales (AdWords) Conversion Page -->
229
+
230
+ <?php
 
 
 
 
231
  // Set the order ID meta after the conversion code has run once.
 
 
232
  update_post_meta( $order_id, '_WGACT_conversion_pixel_fired', 'true' );
233
  } // end if order status
234
  }
235
  }
236
 
237
+ $wgact = new WGACT();