Plugin Directory

Changeset 3380023


Ignore:
Timestamp:
10/17/2025 10:37:33 AM (6 months ago)
Author:
awinglobal
Message:

Updated to 2.0.5

Location:
awin-advertiser-tracking/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • awin-advertiser-tracking/trunk/awin-advertiser-tracking.php

    r3375249 r3380023  
    55 * Plugin URI: https://wordpress.org/plugins/awin-advertiser-tracking
    66 * Description: The Awin Advertiser Tracking plugin allows for seamless integration of our core Advertiser Tracking Suite within WooCommerce.
    7  * Version: 2.0.4
     7 * Version: 2.0.5
    88 * Author: awinglobal
    99 * Author URI: https://profiles.wordpress.org/awinglobal/
     
    1515 */
    1616
    17 define('AWIN_ADVERTISER_TRACKING_VERSION', '2.0.4');
     17define('AWIN_ADVERTISER_TRACKING_VERSION', '2.0.5');
    1818define('AWIN_SLUG', 'awin_advertiser_tracking');
    1919define('AWIN_TEXT_DOMAIN', 'awin-advertiser-tracking');
     
    2727    add_action('admin_menu', 'awin_add_admin_menu');
    2828    add_action('admin_init', 'awin_settings_init');
     29    add_action('admin_enqueue_scripts', 'awin_enqueue_admin_scripts');
    2930    add_action('wp_enqueue_scripts', 'awin_enqueue_journey_tag_script');
    3031    add_action('init', 'awin_process_url_params');
     
    6263            basename(dirname(__FILE__)) . '/lang/'
    6364        );
     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);
    6489    }
    6590
     
    106131        );
    107132
    108         // Add input field for xtype parameter
     133        // Add dropdown field for xtype parameter
    109134        add_settings_field(
    110135            'awin_xtype',
    111136            __('Custom parameter (Optional, Applies to All Transactions)', AWIN_TEXT_DOMAIN),
    112137            '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',
    113147            'awin-plugin-page',
    114148            'awin_plugin-page_section'
     
    156190            $xtype   = isset($options['awin_xtype']) ? sanitize_text_field($options['awin_xtype']) : '';
    157191        ?>
    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>
    162212<p class="description">
    163     Pass a fixed tracking value with every transaction processed through your WooCommerce store.<br><br>
    164213    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.
    165233</p>
    166234<?php
     
    280348        }
    281349
     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
    282426        function awin_thank_you($order_id)
    283427        {
     
    319463               
    320464                // 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);
    323466                if (strlen($xtype) > 0) {
    324467                    $imgUrl .= '&p6=' . urlencode($xtype);
     
    363506                $customParams[] = ''; // p5 (reserved)
    364507               
    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; // p6
     508                // 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
    369512               
    370513                // Build JSON array for custom parameters, filtering out trailing empty values
     
    430573
    431574            // 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);
    434576            if (strlen($xtype) > 0) {
    435577                $query["p6"] = $xtype;
     
    440582            }
    441583
    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);
    443586        }
    444587
  • awin-advertiser-tracking/trunk/readme.txt

    r3375249 r3380023  
    5050
    5151== 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
    5257
    5358= 2.0.4 =
Note: See TracChangeset for help on using the changeset viewer.