Changeset 3380023
- Timestamp:
- 10/17/2025 10:37:33 AM (6 months ago)
- Location:
- awin-advertiser-tracking/trunk
- Files:
-
- 2 edited
-
awin-advertiser-tracking.php (modified) (11 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
awin-advertiser-tracking/trunk/awin-advertiser-tracking.php
r3375249 r3380023 5 5 * Plugin URI: https://wordpress.org/plugins/awin-advertiser-tracking 6 6 * Description: The Awin Advertiser Tracking plugin allows for seamless integration of our core Advertiser Tracking Suite within WooCommerce. 7 * Version: 2.0. 47 * Version: 2.0.5 8 8 * Author: awinglobal 9 9 * Author URI: https://profiles.wordpress.org/awinglobal/ … … 15 15 */ 16 16 17 define('AWIN_ADVERTISER_TRACKING_VERSION', '2.0. 4');17 define('AWIN_ADVERTISER_TRACKING_VERSION', '2.0.5'); 18 18 define('AWIN_SLUG', 'awin_advertiser_tracking'); 19 19 define('AWIN_TEXT_DOMAIN', 'awin-advertiser-tracking'); … … 27 27 add_action('admin_menu', 'awin_add_admin_menu'); 28 28 add_action('admin_init', 'awin_settings_init'); 29 add_action('admin_enqueue_scripts', 'awin_enqueue_admin_scripts'); 29 30 add_action('wp_enqueue_scripts', 'awin_enqueue_journey_tag_script'); 30 31 add_action('init', 'awin_process_url_params'); … … 62 63 basename(dirname(__FILE__)) . '/lang/' 63 64 ); 65 } 66 67 function awin_enqueue_admin_scripts($hook) 68 { 69 // Only enqueue on our plugin settings page 70 if ($hook !== 'settings_page_' . AWIN_SLUG) { 71 return; 72 } 73 74 // Inline JavaScript for xtype dropdown handling 75 $inline_script = " 76 jQuery(document).ready(function($) { 77 $('#awin_xtype').on('change', function() { 78 if (this.value == 'user_defined') { 79 $('#awin_xtype_custom').attr('type', 'text').next('.description').show(); 80 } else { 81 $('#awin_xtype_custom').attr('type', 'hidden').next('.description').hide(); 82 } 83 }); 84 }); 85 "; 86 87 wp_enqueue_script('jquery'); 88 wp_add_inline_script('jquery', $inline_script); 64 89 } 65 90 … … 106 131 ); 107 132 108 // Add inputfield for xtype parameter133 // Add dropdown field for xtype parameter 109 134 add_settings_field( 110 135 'awin_xtype', 111 136 __('Custom parameter (Optional, Applies to All Transactions)', AWIN_TEXT_DOMAIN), 112 137 'awin_xtype_render', 138 'awin-plugin-page', 139 'awin_plugin-page_section' 140 ); 141 142 // Add hidden field for custom xtype value 143 add_settings_field( 144 'awin_xtype_custom', 145 '', 146 'awin_xtype_custom_render', 113 147 'awin-plugin-page', 114 148 'awin_plugin-page_section' … … 156 190 $xtype = isset($options['awin_xtype']) ? sanitize_text_field($options['awin_xtype']) : ''; 157 191 ?> 158 <input type="text" name="awin_settings[awin_xtype]" 159 value="<?php echo esc_attr($xtype); ?>" 160 class="regular-text" 161 placeholder="e.g., store-region, brand-name"> 192 <select id="awin_xtype" name="awin_settings[awin_xtype]"> 193 <option value="">Select an optional Custom parameter</option> 194 <optgroup label="Custom"> 195 <option value="user_defined" <?php selected($xtype, 'user_defined'); ?>>Select to enter your own value</option> 196 </optgroup> 197 <optgroup label="Customer"> 198 <option value="customer_id" <?php selected($xtype, 'customer_id'); ?>>ID</option> 199 <option value="customer_device_type" <?php selected($xtype, 'customer_device_type'); ?>>Device Type (mobile or desktop)</option> 200 <option value="customer_billing_country_code" <?php selected($xtype, 'customer_billing_country_code'); ?>>Billing Country Code</option> 201 <option value="customer_billing_state_code" <?php selected($xtype, 'customer_billing_state_code'); ?>>Billing State Code</option> 202 <option value="customer_billing_city_code" <?php selected($xtype, 'customer_billing_city_code'); ?>>Billing City Name</option> 203 <option value="customer_shipping_country_code" <?php selected($xtype, 'customer_shipping_country_code'); ?>>Shipping Country Code</option> 204 <option value="customer_shipping_state_code" <?php selected($xtype, 'customer_shipping_state_code'); ?>>Shipping State Code</option> 205 <option value="customer_shipping_city_code" <?php selected($xtype, 'customer_shipping_city_code'); ?>>Shipping City Name</option> 206 </optgroup> 207 <optgroup label="Payment"> 208 <option value="payment_type" <?php selected($xtype, 'payment_type'); ?>>Method (cheque, PayPal, Cash on Delivery, etc.)</option> 209 <option value="payment_shipping" <?php selected($xtype, 'payment_shipping'); ?>>Shipping Method (UPS, FedEx, Flat Rate etc.)</option> 210 </optgroup> 211 </select> 162 212 <p class="description"> 163 Pass a fixed tracking value with every transaction processed through your WooCommerce store.<br><br>164 213 This optional field allows you to send a consistent identifier with every tracked sale. This is useful for distinguishing transactions by store region, brand, or other business-specific grouping. The value entered here will be included in all transactions and available in Awin reports. 214 </p> 215 <?php 216 } 217 218 function awin_xtype_custom_render() 219 { 220 $options = get_option(AWIN_SETTINGS_KEY); 221 $xtype = isset($options['awin_xtype']) ? sanitize_text_field($options['awin_xtype']) : ''; 222 $xtype_custom = isset($options['awin_xtype_custom']) ? sanitize_text_field($options['awin_xtype_custom']) : ''; 223 $input_type = ($xtype == 'user_defined') ? 'text' : 'hidden'; 224 ?> 225 <input type="<?php echo $input_type; ?>" 226 id="awin_xtype_custom" 227 name="awin_settings[awin_xtype_custom]" 228 value="<?php echo esc_attr($xtype_custom); ?>" 229 class="regular-text" 230 placeholder="Enter your custom value"> 231 <p class="description" style="display: <?php echo ($xtype == 'user_defined') ? 'block' : 'none'; ?>;"> 232 Pass a fixed tracking value with every transaction processed through your WooCommerce store. 165 233 </p> 166 234 <?php … … 280 348 } 281 349 350 function awin_get_xtype_value($order) 351 { 352 $options = get_option(AWIN_SETTINGS_KEY); 353 $xtype_option = isset($options['awin_xtype']) ? sanitize_text_field($options['awin_xtype']) : ''; 354 $xtype_custom = isset($options['awin_xtype_custom']) ? sanitize_text_field($options['awin_xtype_custom']) : ''; 355 356 if (empty($xtype_option)) { 357 return ''; 358 } 359 360 $xtype_value = ''; 361 362 switch ($xtype_option) { 363 case 'customer_billing_country_code': 364 $xtype_value = $order->get_billing_country(); 365 break; 366 367 case 'customer_billing_state_code': 368 $xtype_value = $order->get_billing_state(); 369 break; 370 371 case 'customer_billing_city_code': 372 $xtype_value = $order->get_billing_city(); 373 break; 374 375 case 'customer_shipping_country_code': 376 $xtype_value = $order->get_shipping_country(); 377 break; 378 379 case 'customer_shipping_state_code': 380 $xtype_value = $order->get_shipping_state(); 381 break; 382 383 case 'customer_shipping_city_code': 384 $xtype_value = $order->get_shipping_city(); 385 break; 386 387 case 'customer_id': 388 $xtype_value = $order->get_user_id(); 389 break; 390 391 case 'customer_device_type': 392 $xtype_value = wp_is_mobile() ? 'mobile' : 'desktop'; 393 break; 394 395 case 'payment_type': 396 $xtype_value = $order->get_payment_method_title(); 397 break; 398 399 case 'payment_shipping': 400 // Get shipping method - try multiple approaches for compatibility 401 $shipping_methods = $order->get_items('shipping'); 402 403 if (!empty($shipping_methods)) { 404 $shipping_method = array_shift($shipping_methods); 405 $xtype_value = $shipping_method->get_method_title(); 406 } else { 407 // Fallback: try to get from order meta 408 $shipping_method = $order->get_shipping_method(); 409 if (!empty($shipping_method)) { 410 $xtype_value = $shipping_method; 411 } 412 } 413 break; 414 415 case 'user_defined': 416 $xtype_value = $xtype_custom; 417 break; 418 419 default: 420 $xtype_value = ''; 421 } 422 423 return $xtype_value; 424 } 425 282 426 function awin_thank_you($order_id) 283 427 { … … 319 463 320 464 // Add xtype parameter if configured 321 $options = get_option(AWIN_SETTINGS_KEY); 322 $xtype = isset($options['awin_xtype']) ? sanitize_text_field($options['awin_xtype']) : ''; 465 $xtype = awin_get_xtype_value($order); 323 466 if (strlen($xtype) > 0) { 324 467 $imgUrl .= '&p6=' . urlencode($xtype); … … 363 506 $customParams[] = ''; // p5 (reserved) 364 507 365 // Add xtype as p6 if configured 366 $ options = get_option(AWIN_SETTINGS_KEY);367 $ xtype = isset($options['awin_xtype']) ? sanitize_text_field($options['awin_xtype']) : '';368 $customParams[] = $ xtype; // p6508 // Add xtype as p6 if configured (URL-encoded for use in tracking URLs) 509 $xtype = awin_get_xtype_value($order); 510 $encoded_xtype = !empty($xtype) ? urlencode($xtype) : ''; 511 $customParams[] = $encoded_xtype; // p6 369 512 370 513 // Build JSON array for custom parameters, filtering out trailing empty values … … 430 573 431 574 // Add xtype parameter if configured 432 $options = get_option(AWIN_SETTINGS_KEY); 433 $xtype = isset($options['awin_xtype']) ? sanitize_text_field($options['awin_xtype']) : ''; 575 $xtype = awin_get_xtype_value($order); 434 576 if (strlen($xtype) > 0) { 435 577 $query["p6"] = $xtype; … … 440 582 } 441 583 442 wp_remote_get("https://www.awin1.com/sread.php?" . http_build_query($query)); 584 $final_url = "https://www.awin1.com/sread.php?" . http_build_query($query); 585 wp_remote_get($final_url); 443 586 } 444 587 -
awin-advertiser-tracking/trunk/readme.txt
r3375249 r3380023 50 50 51 51 == Changelog == 52 53 = 2.0.5 = 54 * Enhanced Custom Parameter (p6) with dynamic dropdown selection 55 * Added 11 predefined tracking options: customer data (billing/shipping country, state, city), payment method, shipping method, device type, and customer ID 56 * Improved admin UI with conditional input field for custom values 52 57 53 58 = 2.0.4 =
Note: See TracChangeset
for help on using the changeset viewer.