Version Description
Download this release
Release Info
Developer | alekv |
Plugin | 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
- readme.txt +8 -5
- 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.
|
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
|
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
|
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
|
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
|
7 |
-
Author URI:
|
8 |
-
Version: 1.
|
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 |
-
//
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
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("]]>", "]]>", $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 |
-
|
51 |
-
|
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 |
-
|
61 |
-
|
62 |
-
//
|
63 |
-
add_action('
|
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',
|
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(
|
|
|
|
|
|
|
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 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
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 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
138 |
</div>
|
139 |
|
140 |
<?php
|
141 |
-
|
142 |
-
|
143 |
}
|
144 |
|
145 |
|
146 |
// add the admin settings and such
|
147 |
-
function wgact_plugin_admin_init(){
|
148 |
-
|
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(
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
195 |
$conversion_id = $opt['text_string'];
|
|
|
196 |
return $conversion_id;
|
197 |
}
|
198 |
|
199 |
-
private function get_conversion_label(){
|
200 |
-
$opt
|
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 |
-
|
217 |
-
|
218 |
// get order from URL and evaluate order total
|
219 |
-
$order
|
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 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
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; ?>&currency_code=<?php echo $order->get_order_currency(); ?>&label=<?php echo $conversion_label; ?>&guid=ON&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();
|
|
|
|