Changeset 2067784
- Timestamp:
- 04/12/2019 12:17:33 PM (7 years ago)
- Location:
- storespot
- Files:
-
- 6 deleted
- 8 edited
- 1 copied
-
tags/1.1.1/admin/class-storespot-async.php (deleted)
-
tags/1.1.1/admin/class-storespot-productfeed.php (deleted)
-
tags/1.1.2 (copied) (copied from storespot/trunk)
-
tags/1.1.2/admin/class-storespot-async.php (deleted)
-
tags/1.1.2/admin/class-storespot-productfeed.php (deleted)
-
tags/1.1.2/includes/class-storespot.php (modified) (1 diff)
-
tags/1.1.2/public/class-storespot-events.php (modified) (4 diffs)
-
tags/1.1.2/readme.txt (modified) (2 diffs)
-
tags/1.1.2/storespot.php (modified) (2 diffs)
-
trunk/admin/class-storespot-async.php (deleted)
-
trunk/admin/class-storespot-productfeed.php (deleted)
-
trunk/includes/class-storespot.php (modified) (1 diff)
-
trunk/public/class-storespot-events.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/storespot.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
storespot/tags/1.1.2/includes/class-storespot.php
r2062753 r2067784 73 73 $this->loader->add_action( 'wp_head', $plugin_public, 'render_facebook_pixel' ); 74 74 $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' ); 77 77 $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 ); 80 79 $this->loader->add_action( 'woocommerce_after_checkout_form', $plugin_public, 'render_initiate_checkout_event' ); 81 80 $this->loader->add_action( 'woocommerce_thankyou', $plugin_public, 'render_purchase_event' ); -
storespot/tags/1.1.2/public/class-storespot-events.php
r2062753 r2067784 95 95 } 96 96 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 98 137 global $woocommerce; 99 138 $products = $woocommerce->cart->get_cart(); … … 111 150 $params['value'] = array_sum( $prices ); 112 151 $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();170 152 $params['num_items'] = $woocommerce->cart->get_cart_contents_count(); 171 153 … … 195 177 196 178 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 " 200 181 <!-- StoreSpot Facebook Listener Begin --> 201 182 <script type='text/javascript'> 202 183 document.addEventListener('DOMContentLoaded', function() { 203 184 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 ); 209 191 }); 210 192 }); … … 212 194 </script> 213 195 <!-- StoreSpot Facebook Listener End --> 214 "; 215 216 } 196 "; 197 217 198 } 218 199 } -
storespot/tags/1.1.2/readme.txt
r2062753 r2067784 5 5 Tested up to: 5.1 6 6 Requires PHP: 5.6 7 Stable tag: 1.1. 17 Stable tag: 1.1.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 49 49 50 50 == Changelog == 51 = 1.1.2 = 52 * Update: cart event values per product 53 51 54 = 1.1.1 = 52 55 * Support for off-site feed generation -
storespot/tags/1.1.2/storespot.php
r2062753 r2067784 4 4 * Plugin URI: https://storespot.io/ 5 5 * Description: Stop leaving money on the table. Automate your retargeting ads with StoreSpot. 6 * Version: 1.1. 16 * Version: 1.1.2 7 7 * Author: StoreSpot 8 8 **/ … … 11 11 if ( ! defined( 'WPINC' ) ) { die; } 12 12 13 define( 'STORESPOT_VERSION', '1.1. 1' );13 define( 'STORESPOT_VERSION', '1.1.2' ); 14 14 15 15 function activate_storespot() { -
storespot/trunk/includes/class-storespot.php
r2062753 r2067784 73 73 $this->loader->add_action( 'wp_head', $plugin_public, 'render_facebook_pixel' ); 74 74 $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' ); 77 77 $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 ); 80 79 $this->loader->add_action( 'woocommerce_after_checkout_form', $plugin_public, 'render_initiate_checkout_event' ); 81 80 $this->loader->add_action( 'woocommerce_thankyou', $plugin_public, 'render_purchase_event' ); -
storespot/trunk/public/class-storespot-events.php
r2062753 r2067784 95 95 } 96 96 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 98 137 global $woocommerce; 99 138 $products = $woocommerce->cart->get_cart(); … … 111 150 $params['value'] = array_sum( $prices ); 112 151 $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();170 152 $params['num_items'] = $woocommerce->cart->get_cart_contents_count(); 171 153 … … 195 177 196 178 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 " 200 181 <!-- StoreSpot Facebook Listener Begin --> 201 182 <script type='text/javascript'> 202 183 document.addEventListener('DOMContentLoaded', function() { 203 184 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 ); 209 191 }); 210 192 }); … … 212 194 </script> 213 195 <!-- StoreSpot Facebook Listener End --> 214 "; 215 216 } 196 "; 197 217 198 } 218 199 } -
storespot/trunk/readme.txt
r2062753 r2067784 5 5 Tested up to: 5.1 6 6 Requires PHP: 5.6 7 Stable tag: 1.1. 17 Stable tag: 1.1.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 49 49 50 50 == Changelog == 51 = 1.1.2 = 52 * Update: cart event values per product 53 51 54 = 1.1.1 = 52 55 * Support for off-site feed generation -
storespot/trunk/storespot.php
r2062753 r2067784 4 4 * Plugin URI: https://storespot.io/ 5 5 * Description: Stop leaving money on the table. Automate your retargeting ads with StoreSpot. 6 * Version: 1.1. 16 * Version: 1.1.2 7 7 * Author: StoreSpot 8 8 **/ … … 11 11 if ( ! defined( 'WPINC' ) ) { die; } 12 12 13 define( 'STORESPOT_VERSION', '1.1. 1' );13 define( 'STORESPOT_VERSION', '1.1.2' ); 14 14 15 15 function activate_storespot() {
Note: See TracChangeset
for help on using the changeset viewer.