Plugin Directory

Changeset 2520568


Ignore:
Timestamp:
04/23/2021 07:19:44 PM (5 years ago)
Author:
convertize
Message:

support variant stock

Location:
nudgify
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • nudgify/tags/1.1.1/nudgify.php

    r2515785 r2520568  
    44Description: Install Nudgify on your WordPress website in less then 10 seconds. Integrate unique tracking code of Nudgify into every page of your website in one click.
    55Author: Nudgify
    6 Version: 1.1.0
     6Version: 1.1.1
    77Author URI: https://nudgify.com
    88License: GPLv2
     
    1212defined('ABSPATH') or die('Restricted access!');
    1313
    14 define('NUDGIFY_PLUGIN_VERSION', '1.1.0');
     14define('NUDGIFY_PLUGIN_VERSION', '1.1.1');
    1515define('NUDGIFY_PLUGIN_SLUG', 'nudgify');
    1616define('NUDGIFY_PLUGIN_URL', plugin_dir_url(__FILE__));
     
    152152                    $this->product = wc_get_product($post->ID);
    153153
     154                    $productStock = $this->get_product_stock();
     155
     156                    if (is_null($productStock) && $this->product->is_type('variable')) {
     157                        $productStock = 0;
     158                        $variations = $this->product->get_available_variations();
     159                        foreach ($variations as $variation) {
     160                            $productStock += $variation['max_qty'];
     161                        }
     162                    }
     163
    154164                    $pixelData['data']['product'] = [
    155165                        'id' => $this->product->get_id(),
    156                         'stock' => $this->get_product_stock(),
     166                        'stock' => $productStock,
    157167                        'image' => $this->get_product_image($this->product)
    158168                    ];
    159169                }
    160170            }
    161 
    162171            $pixelDataString = $this->pixel_data_string($pixelData);
    163172
    164173            echo implode("\n", array(
    165174                '<script>',
    166                 "   {$pixelDataString} ",
    167                 '   (function(w){',
    168                 '       var k="nudgify",n=w[k]||(w[k]={});',
    169                 "       n.uuid={$uuid};",
    170                 '       var d=document,s=d.createElement("script");',
    171                 "       s.src={$url};",
    172                 '       s.async=1;',
    173                 '       s.charset="utf-8";',
    174                 '       d.getElementsByTagName("head")[0].appendChild(s)',
    175                 '   })(window)',
     175                "    {$pixelDataString} ",
     176                '    jQuery(document).on("show_variation", function (event, variant) {',
     177                '        if (!variant.is_in_stock) return; ',
     178                '        window.nudgify.product({',
     179                '            id: variant.variation_id || null,',
     180                '            stock: variant.max_qty || null,',
     181                '            image: variant.image.thumb_src || null,',
     182                '        })',
     183                '    });',
     184                '    (function(w){',
     185                '        var k="nudgify",n=w[k]||(w[k]={});',
     186                "        n.uuid={$uuid};",
     187                '        var d=document,s=d.createElement("script");',
     188                "        s.src={$url};",
     189                '        s.async=1;',
     190                '        s.charset="utf-8";',
     191                '        d.getElementsByTagName("head")[0].appendChild(s)',
     192                '    })(window)',
    176193                '</script>',
    177194            ));
  • nudgify/tags/1.1.1/readme.txt

    r2515785 r2520568  
    55Requires at least: 4.6
    66Tested up to: 5.7.1
    7 Stable tag: 1.1.0
     7Stable tag: 1.1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • nudgify/trunk/nudgify.php

    r2515785 r2520568  
    44Description: Install Nudgify on your WordPress website in less then 10 seconds. Integrate unique tracking code of Nudgify into every page of your website in one click.
    55Author: Nudgify
    6 Version: 1.1.0
     6Version: 1.1.1
    77Author URI: https://nudgify.com
    88License: GPLv2
     
    1212defined('ABSPATH') or die('Restricted access!');
    1313
    14 define('NUDGIFY_PLUGIN_VERSION', '1.1.0');
     14define('NUDGIFY_PLUGIN_VERSION', '1.1.1');
    1515define('NUDGIFY_PLUGIN_SLUG', 'nudgify');
    1616define('NUDGIFY_PLUGIN_URL', plugin_dir_url(__FILE__));
     
    152152                    $this->product = wc_get_product($post->ID);
    153153
     154                    $productStock = $this->get_product_stock();
     155
     156                    if (is_null($productStock) && $this->product->is_type('variable')) {
     157                        $productStock = 0;
     158                        $variations = $this->product->get_available_variations();
     159                        foreach ($variations as $variation) {
     160                            $productStock += $variation['max_qty'];
     161                        }
     162                    }
     163
    154164                    $pixelData['data']['product'] = [
    155165                        'id' => $this->product->get_id(),
    156                         'stock' => $this->get_product_stock(),
     166                        'stock' => $productStock,
    157167                        'image' => $this->get_product_image($this->product)
    158168                    ];
    159169                }
    160170            }
    161 
    162171            $pixelDataString = $this->pixel_data_string($pixelData);
    163172
    164173            echo implode("\n", array(
    165174                '<script>',
    166                 "   {$pixelDataString} ",
    167                 '   (function(w){',
    168                 '       var k="nudgify",n=w[k]||(w[k]={});',
    169                 "       n.uuid={$uuid};",
    170                 '       var d=document,s=d.createElement("script");',
    171                 "       s.src={$url};",
    172                 '       s.async=1;',
    173                 '       s.charset="utf-8";',
    174                 '       d.getElementsByTagName("head")[0].appendChild(s)',
    175                 '   })(window)',
     175                "    {$pixelDataString} ",
     176                '    jQuery(document).on("show_variation", function (event, variant) {',
     177                '        if (!variant.is_in_stock) return; ',
     178                '        window.nudgify.product({',
     179                '            id: variant.variation_id || null,',
     180                '            stock: variant.max_qty || null,',
     181                '            image: variant.image.thumb_src || null,',
     182                '        })',
     183                '    });',
     184                '    (function(w){',
     185                '        var k="nudgify",n=w[k]||(w[k]={});',
     186                "        n.uuid={$uuid};",
     187                '        var d=document,s=d.createElement("script");',
     188                "        s.src={$url};",
     189                '        s.async=1;',
     190                '        s.charset="utf-8";',
     191                '        d.getElementsByTagName("head")[0].appendChild(s)',
     192                '    })(window)',
    176193                '</script>',
    177194            ));
  • nudgify/trunk/readme.txt

    r2515785 r2520568  
    55Requires at least: 4.6
    66Tested up to: 5.7.1
    7 Stable tag: 1.1.0
     7Stable tag: 1.1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.