Plugin Directory

Changeset 2067784


Ignore:
Timestamp:
04/12/2019 12:17:33 PM (7 years ago)
Author:
storespot
Message:

1.1.2"

Location:
storespot
Files:
6 deleted
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • storespot/tags/1.1.2/includes/class-storespot.php

    r2062753 r2067784  
    7373            $this->loader->add_action( 'wp_head', $plugin_public, 'render_facebook_pixel' );
    7474            $this->loader->add_action( 'wp_footer', $plugin_public, 'render_facebook_pixel_noscript' );
    75             $this->loader->add_action( 'woocommerce_after_single_product', $plugin_public, 'render_product_view_event');
    76             $this->loader->add_action( 'woocommerce_after_shop_loop', $plugin_public, 'render_category_view_event');
     75            $this->loader->add_action( 'woocommerce_after_single_product', $plugin_public, 'render_product_view_event' );
     76            $this->loader->add_action( 'woocommerce_after_shop_loop', $plugin_public, 'render_category_view_event' );
    7777            $this->loader->add_action( 'pre_get_posts', $plugin_public, 'render_search_event' );
    78             $this->loader->add_action( 'woocommerce_add_to_cart', $plugin_public, 'render_add_to_cart_event' );
    79             $this->loader->add_action( 'woocommerce_after_cart', $plugin_public, 'render_add_to_cart_redirect_event' );
     78            $this->loader->add_action( 'woocommerce_add_to_cart', $plugin_public, 'render_add_to_cart_event', 10, 4 );
    8079            $this->loader->add_action( 'woocommerce_after_checkout_form', $plugin_public, 'render_initiate_checkout_event' );
    8180            $this->loader->add_action( 'woocommerce_thankyou', $plugin_public, 'render_purchase_event' );
  • storespot/tags/1.1.2/public/class-storespot-events.php

    r2062753 r2067784  
    9595    }
    9696
    97     public function render_add_to_cart_event() {
     97    private function stsp_get_cart_contents( $product, $qty=1 ) {
     98        $stsp_id = $this->get_facebook_content_id( $product );
     99        $price = number_format( $product->get_price(), 2) * $qty;
     100
     101        return [
     102            'content_ids'   => json_encode([ $stsp_id ]),
     103            'content_type'  => 'product',
     104            'value'         => $price,
     105            'currency'      => get_woocommerce_currency()
     106        ];
     107    }
     108
     109    public function render_add_to_cart_event($key, $product_id, $qty, $variation_id) {
     110        $item_id = $variation_id == 0 ? $product_id : $variation_id;
     111        $product = wc_get_product( $item_id );
     112        $params = $this->stsp_get_cart_contents( $product, $qty );
     113        $this->facebook_pixel->event_code( 'AddToCart', $params );
     114    }
     115
     116    public function render_ajax_add_to_cart_event() {
     117
     118        ob_start();
     119
     120        $params = [];
     121        if( array_key_exists( 'item', $_POST ) ) {
     122            $product = wc_get_product( $_POST['item'] );
     123            $params = $this->stsp_get_cart_contents( $product );
     124        }
     125
     126        echo $this->facebook_pixel->ajax_event_code( 'AddToCart', $params );
     127
     128        $pixel = ob_get_clean();
     129        wp_send_json($pixel);
     130    }
     131
     132    public function render_initiate_checkout_event() {
     133        if ( $this->facebook_pixel->check_last_event( 'InitiateCheckout' ) ) {
     134            return;
     135        }
     136
    98137        global $woocommerce;
    99138        $products = $woocommerce->cart->get_cart();
     
    111150        $params['value'] = array_sum( $prices );
    112151        $params['currency'] = get_woocommerce_currency();
    113         $this->facebook_pixel->event_code( 'AddToCart', $params );
    114     }
    115 
    116     public function render_add_to_cart_redirect_event() {
    117         $redirect = get_option( 'woocommerce_cart_redirect_after_add', 'no' );
    118         if ( $redirect == 'yes' ) {
    119             $this->render_add_to_cart_event();
    120         }
    121     }
    122 
    123     public function render_ajax_add_to_cart_event() {
    124 
    125         global $woocommerce;
    126         $products = $woocommerce->cart->get_cart();
    127 
    128         ob_start();
    129 
    130         $product_ids = array();
    131         $prices = array();
    132         foreach ( $products as $item ) {
    133             $product = $item['data'];
    134             $product_ids[] = $this->get_facebook_content_id( $product );
    135             $prices[] = number_format( $product->get_price(), 2) * $item['quantity'];
    136         }
    137 
    138         $params = array();
    139         $params['content_ids'] = json_encode( $product_ids );
    140         $params['content_type'] = 'product';
    141         $params['value'] = array_sum( $prices );
    142         $params['currency'] = get_woocommerce_currency();
    143 
    144         echo $this->facebook_pixel->ajax_event_code( 'AddToCart', $params );
    145 
    146         $pixel = ob_get_clean();
    147         wp_send_json($pixel);
    148     }
    149 
    150     public function render_initiate_checkout_event() {
    151         if ( $this->facebook_pixel->check_last_event( 'InitiateCheckout' ) ) {
    152             return;
    153         }
    154 
    155         global $woocommerce;
    156         $products = $woocommerce->cart->get_cart();
    157         $product_ids = array();
    158         $prices = array();
    159         foreach ( $products as $item ) {
    160             $product = $item['data'];
    161             $product_ids[] = $this->get_facebook_content_id( $product );
    162             $prices[] = number_format( $product->get_price(), 2) * $item['quantity'];
    163         }
    164 
    165         $params = array();
    166         $params['content_ids'] = json_encode( $product_ids );
    167         $params['content_type'] = 'product';
    168         $params['value'] = array_sum( $prices );
    169         $params['currency'] = get_woocommerce_currency();
    170152        $params['num_items'] = $woocommerce->cart->get_cart_contents_count();
    171153
     
    195177
    196178    public function custom_jquery_add_to_cart_script(){
    197         if ( is_front_page() || is_shop() || is_product_category() || is_product_tag() ) {
    198 
    199             echo "
     179
     180        echo "
    200181<!-- StoreSpot Facebook Listener Begin -->
    201182<script type='text/javascript'>
    202183document.addEventListener('DOMContentLoaded', function() {
    203184  jQuery && jQuery(function($){
    204     $('body').on('added_to_cart', function(event) {
    205       // Ajax action.
    206       $.get('?wc-ajax=stsp_add_to_cart_event', function(data) {
    207         $('head').append(data);
    208       });
     185    $('body').on('adding_to_cart', function(event, data) {
     186      $.post(
     187        '?wc-ajax=stsp_add_to_cart_event',
     188        {item: data.context.dataset.product_id},
     189        function(fb) { $('head').append(fb); }
     190      );
    209191    });
    210192  });
     
    212194</script>
    213195<!-- StoreSpot Facebook Listener End -->
    214             ";
    215 
    216         }
     196        ";
     197
    217198    }
    218199}
  • storespot/tags/1.1.2/readme.txt

    r2062753 r2067784  
    55Tested up to: 5.1
    66Requires PHP: 5.6
    7 Stable tag: 1.1.1
     7Stable tag: 1.1.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4949
    5050== Changelog ==
     51= 1.1.2 =
     52* Update: cart event values per product
     53
    5154= 1.1.1 =
    5255* Support for off-site feed generation
  • storespot/tags/1.1.2/storespot.php

    r2062753 r2067784  
    44 * Plugin URI:   https://storespot.io/
    55 * Description:  Stop leaving money on the table. Automate your retargeting ads with StoreSpot.
    6  * Version:      1.1.1
     6 * Version:      1.1.2
    77 * Author:       StoreSpot
    88**/
     
    1111if ( ! defined( 'WPINC' ) ) { die; }
    1212
    13 define( 'STORESPOT_VERSION', '1.1.1' );
     13define( 'STORESPOT_VERSION', '1.1.2' );
    1414
    1515function activate_storespot() {
  • storespot/trunk/includes/class-storespot.php

    r2062753 r2067784  
    7373            $this->loader->add_action( 'wp_head', $plugin_public, 'render_facebook_pixel' );
    7474            $this->loader->add_action( 'wp_footer', $plugin_public, 'render_facebook_pixel_noscript' );
    75             $this->loader->add_action( 'woocommerce_after_single_product', $plugin_public, 'render_product_view_event');
    76             $this->loader->add_action( 'woocommerce_after_shop_loop', $plugin_public, 'render_category_view_event');
     75            $this->loader->add_action( 'woocommerce_after_single_product', $plugin_public, 'render_product_view_event' );
     76            $this->loader->add_action( 'woocommerce_after_shop_loop', $plugin_public, 'render_category_view_event' );
    7777            $this->loader->add_action( 'pre_get_posts', $plugin_public, 'render_search_event' );
    78             $this->loader->add_action( 'woocommerce_add_to_cart', $plugin_public, 'render_add_to_cart_event' );
    79             $this->loader->add_action( 'woocommerce_after_cart', $plugin_public, 'render_add_to_cart_redirect_event' );
     78            $this->loader->add_action( 'woocommerce_add_to_cart', $plugin_public, 'render_add_to_cart_event', 10, 4 );
    8079            $this->loader->add_action( 'woocommerce_after_checkout_form', $plugin_public, 'render_initiate_checkout_event' );
    8180            $this->loader->add_action( 'woocommerce_thankyou', $plugin_public, 'render_purchase_event' );
  • storespot/trunk/public/class-storespot-events.php

    r2062753 r2067784  
    9595    }
    9696
    97     public function render_add_to_cart_event() {
     97    private function stsp_get_cart_contents( $product, $qty=1 ) {
     98        $stsp_id = $this->get_facebook_content_id( $product );
     99        $price = number_format( $product->get_price(), 2) * $qty;
     100
     101        return [
     102            'content_ids'   => json_encode([ $stsp_id ]),
     103            'content_type'  => 'product',
     104            'value'         => $price,
     105            'currency'      => get_woocommerce_currency()
     106        ];
     107    }
     108
     109    public function render_add_to_cart_event($key, $product_id, $qty, $variation_id) {
     110        $item_id = $variation_id == 0 ? $product_id : $variation_id;
     111        $product = wc_get_product( $item_id );
     112        $params = $this->stsp_get_cart_contents( $product, $qty );
     113        $this->facebook_pixel->event_code( 'AddToCart', $params );
     114    }
     115
     116    public function render_ajax_add_to_cart_event() {
     117
     118        ob_start();
     119
     120        $params = [];
     121        if( array_key_exists( 'item', $_POST ) ) {
     122            $product = wc_get_product( $_POST['item'] );
     123            $params = $this->stsp_get_cart_contents( $product );
     124        }
     125
     126        echo $this->facebook_pixel->ajax_event_code( 'AddToCart', $params );
     127
     128        $pixel = ob_get_clean();
     129        wp_send_json($pixel);
     130    }
     131
     132    public function render_initiate_checkout_event() {
     133        if ( $this->facebook_pixel->check_last_event( 'InitiateCheckout' ) ) {
     134            return;
     135        }
     136
    98137        global $woocommerce;
    99138        $products = $woocommerce->cart->get_cart();
     
    111150        $params['value'] = array_sum( $prices );
    112151        $params['currency'] = get_woocommerce_currency();
    113         $this->facebook_pixel->event_code( 'AddToCart', $params );
    114     }
    115 
    116     public function render_add_to_cart_redirect_event() {
    117         $redirect = get_option( 'woocommerce_cart_redirect_after_add', 'no' );
    118         if ( $redirect == 'yes' ) {
    119             $this->render_add_to_cart_event();
    120         }
    121     }
    122 
    123     public function render_ajax_add_to_cart_event() {
    124 
    125         global $woocommerce;
    126         $products = $woocommerce->cart->get_cart();
    127 
    128         ob_start();
    129 
    130         $product_ids = array();
    131         $prices = array();
    132         foreach ( $products as $item ) {
    133             $product = $item['data'];
    134             $product_ids[] = $this->get_facebook_content_id( $product );
    135             $prices[] = number_format( $product->get_price(), 2) * $item['quantity'];
    136         }
    137 
    138         $params = array();
    139         $params['content_ids'] = json_encode( $product_ids );
    140         $params['content_type'] = 'product';
    141         $params['value'] = array_sum( $prices );
    142         $params['currency'] = get_woocommerce_currency();
    143 
    144         echo $this->facebook_pixel->ajax_event_code( 'AddToCart', $params );
    145 
    146         $pixel = ob_get_clean();
    147         wp_send_json($pixel);
    148     }
    149 
    150     public function render_initiate_checkout_event() {
    151         if ( $this->facebook_pixel->check_last_event( 'InitiateCheckout' ) ) {
    152             return;
    153         }
    154 
    155         global $woocommerce;
    156         $products = $woocommerce->cart->get_cart();
    157         $product_ids = array();
    158         $prices = array();
    159         foreach ( $products as $item ) {
    160             $product = $item['data'];
    161             $product_ids[] = $this->get_facebook_content_id( $product );
    162             $prices[] = number_format( $product->get_price(), 2) * $item['quantity'];
    163         }
    164 
    165         $params = array();
    166         $params['content_ids'] = json_encode( $product_ids );
    167         $params['content_type'] = 'product';
    168         $params['value'] = array_sum( $prices );
    169         $params['currency'] = get_woocommerce_currency();
    170152        $params['num_items'] = $woocommerce->cart->get_cart_contents_count();
    171153
     
    195177
    196178    public function custom_jquery_add_to_cart_script(){
    197         if ( is_front_page() || is_shop() || is_product_category() || is_product_tag() ) {
    198 
    199             echo "
     179
     180        echo "
    200181<!-- StoreSpot Facebook Listener Begin -->
    201182<script type='text/javascript'>
    202183document.addEventListener('DOMContentLoaded', function() {
    203184  jQuery && jQuery(function($){
    204     $('body').on('added_to_cart', function(event) {
    205       // Ajax action.
    206       $.get('?wc-ajax=stsp_add_to_cart_event', function(data) {
    207         $('head').append(data);
    208       });
     185    $('body').on('adding_to_cart', function(event, data) {
     186      $.post(
     187        '?wc-ajax=stsp_add_to_cart_event',
     188        {item: data.context.dataset.product_id},
     189        function(fb) { $('head').append(fb); }
     190      );
    209191    });
    210192  });
     
    212194</script>
    213195<!-- StoreSpot Facebook Listener End -->
    214             ";
    215 
    216         }
     196        ";
     197
    217198    }
    218199}
  • storespot/trunk/readme.txt

    r2062753 r2067784  
    55Tested up to: 5.1
    66Requires PHP: 5.6
    7 Stable tag: 1.1.1
     7Stable tag: 1.1.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4949
    5050== Changelog ==
     51= 1.1.2 =
     52* Update: cart event values per product
     53
    5154= 1.1.1 =
    5255* Support for off-site feed generation
  • storespot/trunk/storespot.php

    r2062753 r2067784  
    44 * Plugin URI:   https://storespot.io/
    55 * Description:  Stop leaving money on the table. Automate your retargeting ads with StoreSpot.
    6  * Version:      1.1.1
     6 * Version:      1.1.2
    77 * Author:       StoreSpot
    88**/
     
    1111if ( ! defined( 'WPINC' ) ) { die; }
    1212
    13 define( 'STORESPOT_VERSION', '1.1.1' );
     13define( 'STORESPOT_VERSION', '1.1.2' );
    1414
    1515function activate_storespot() {
Note: See TracChangeset for help on using the changeset viewer.