Changeset 2309641
- Timestamp:
- 05/21/2020 05:44:45 PM (6 years ago)
- Location:
- brainity-boost-ads/trunk
- Files:
-
- 3 edited
-
brainity.php (modified) (3 diffs)
-
pixel/FacebookWordpressPixelInjection.php (modified) (12 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
brainity-boost-ads/trunk/brainity.php
r2296756 r2309641 9 9 Author: Brainity 10 10 Author URI: https://www.brainity.co 11 Version: 1.0. 411 Version: 1.0.5 12 12 */ 13 13 … … 66 66 )); 67 67 }); 68 69 add_action('rest_api_init', function () { 70 register_rest_route('brainity/v1', '/settings', array( 71 'methods' => 'GET', 72 'callback' => array(__CLASS__, 'get_settings'), 73 )); 74 75 register_rest_route('brainity/v1', '/settings', array( 76 'methods' => 'POST', 77 'callback' => array(__CLASS__, 'set_settings'), 78 )); 79 }); 68 80 } 69 81 … … 96 108 97 109 echo($csv); 110 exit; 111 } 112 113 public static function get_settings($data) 114 { 115 header('Content-type: application/json'); 116 117 $token = $data->get_param('token'); 118 119 if (empty($token)) { 120 return new WP_REST_Response('Not found', 404); 121 } 122 123 global $wpdb; 124 125 $table_name = $wpdb->prefix . 'brainity'; 126 127 $config = $wpdb->get_results("SELECT * FROM $table_name "); 128 129 if ($config[0]->token !== $token) { 130 return new WP_REST_Response('Not found', 404); 131 } 132 133 if (count($config) === 0) { 134 return new WP_REST_Response('Not found', 404); 135 } 136 137 if ($config[0]->token !== $token) { 138 return new WP_REST_Response('Not found', 404); 139 } 140 141 $config[0]->facebook_for_woocomerce = get_option( 142 'facebook_config', 143 array( 144 'pixel_id' => '0' 145 ) 146 ); 147 148 echo(json_encode($config[0])); 149 exit; 150 } 151 152 public static function set_settings($data) 153 { 154 header('Content-type: application/json'); 155 156 $token = $data->get_param('token'); 157 158 if (empty($token)) { 159 return new WP_REST_Response('Not found', 404); 160 } 161 162 $pixel = $data->get_param('pixel_id'); 163 164 $setPixelFacebookForWoocomer = $data->get_param('set_facebook_for_woocomerce'); 165 if (!empty($setPixelFacebookForWoocomer) && $setPixelFacebookForWoocomer) { 166 $pixelFacebookForWoocomer = $data->get_param('facebook_for_woocomerce'); 167 168 $options = get_option( 169 'facebook_config', 170 array( 171 'pixel_id' => '0' 172 ) 173 ); 174 175 $options['pixel_id'] = $pixelFacebookForWoocomer; 176 update_option('facebook_config', $options); 177 } 178 179 global $wpdb; 180 181 $table_name = $wpdb->prefix . 'brainity'; 182 183 $config = $wpdb->get_results("SELECT * FROM $table_name "); 184 if ($config[0]->token !== $token) { 185 return new WP_REST_Response('Not found', 404); 186 } 187 188 if (empty($pixel)) { 189 $wpdb->query( 190 $wpdb->prepare("UPDATE $table_name SET pixel_id = NULL") 191 ); 192 } else { 193 $wpdb->query( 194 $wpdb->prepare("UPDATE $table_name SET pixel_id = %s", $pixel) 195 ); 196 } 197 198 $config = $wpdb->get_results("SELECT * FROM $table_name "); 199 if (count($config) === 0) { 200 return new WP_REST_Response('Not found', 404); 201 } 202 203 if ($config[0]->token !== $token) { 204 return new WP_REST_Response('Not found', 404); 205 } 206 207 $config[0]->facebook_for_woocomerce = get_option( 208 'facebook_config', 209 array( 210 'pixel_id' => '0' 211 ) 212 ); 213 echo(json_encode($config[0])); 98 214 exit; 99 215 } -
brainity-boost-ads/trunk/pixel/FacebookWordpressPixelInjection.php
r2243986 r2309641 33 33 /*add_action('pre_get_posts', 34 34 array($this, 'inject_search_event'));*/ 35 add_action('woocommerce_after_cart', 36 array($this, 'inject_add_to_cart_redirect_event')); 37 add_action('woocommerce_add_to_cart', 38 array($this, 'inject_add_to_cart_event'), self::FB_PRIORITY_HIGH); 39 add_action('wc_ajax_fb_inject_add_to_cart_event', 40 array($this, 'inject_ajax_add_to_cart_event'), self::FB_PRIORITY_HIGH); 35 36 // AddToCart events 37 add_action( 'woocommerce_add_to_cart', [ $this, 'inject_add_to_cart_event' ], 40, 4 ); 38 // AddToCart while AJAX is enabled 39 add_action( 'woocommerce_ajax_added_to_cart', [ $this, 'add_filter_for_add_to_cart_fragments' ] ); 40 // AddToCart while using redirect to cart page 41 if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) { 42 add_filter( 'woocommerce_add_to_cart_redirect', [ $this, 'set_last_product_added_to_cart_upon_redirect' ], 10, 2 ); 43 add_action( 'woocommerce_ajax_added_to_cart', [ $this, 'set_last_product_added_to_cart_upon_ajax_redirect' ] ); 44 add_action( 'woocommerce_after_cart', [ $this, 'inject_add_to_cart_redirect_event' ], 10, 2 ); 45 } 46 41 47 add_action('woocommerce_after_checkout_form', 42 48 array($this, 'inject_initiate_checkout_event')); … … 50 56 public function injectPixelCode() 51 57 { 52 53 if ( 54 (isset(self::$renderCache[0]) && 55 self::$renderCache[0] === true) || 58 if ( 56 59 empty(FacebookPixel::getPixelId()) 57 60 ) { … … 67 70 public function injectPixelNoscriptCode() 68 71 { 69 if ( 70 (isset(self::$renderCache[0]) && 71 self::$renderCache[0] === true) || 72 if ( 72 73 empty(FacebookPixel::getPixelId()) 73 74 ) { … … 82 83 public function inject_view_content_event() 83 84 { 84 if ( 85 (isset(self::$renderCache[0]) && 86 self::$renderCache[0] === true) || 87 empty(FacebookPixel::getPixelId()) 88 ) { 89 return; 90 } 91 global $post; 85 global $post; 86 if ( 87 empty(FacebookPixel::getPixelId() || !isset($post->ID)) 88 ) { 89 return; 90 } 91 92 92 $product = wc_get_product($post->ID); 93 93 $content_type = 'product_group'; … … 119 119 { 120 120 if ( 121 (isset(self::$renderCache[0]) &&122 self::$renderCache[0] === true) ||123 121 empty(FacebookPixel::getPixelId()) 124 122 ) { … … 170 168 { 171 169 if ( 172 (isset(self::$renderCache[0]) &&173 self::$renderCache[0] === true) ||174 170 empty(FacebookPixel::getPixelId()) 175 171 ) { … … 188 184 { 189 185 if ( 190 (isset(self::$renderCache[0]) &&191 self::$renderCache[0] === true) ||192 186 empty(FacebookPixel::getPixelId()) 193 187 ) { … … 207 201 208 202 /** 203 * Setups a filter to add an add to cart fragment whenever a product is added to the cart through Ajax. 204 * 205 * @see \WC_Facebookcommerce_EventsTracker::add_add_to_cart_event_fragment 206 * 207 * @internal 208 * 209 * @since 1.10.2 210 */ 211 public function add_filter_for_add_to_cart_fragments() { 212 213 if ( 'no' === get_option( 'woocommerce_cart_redirect_after_add' ) ) { 214 add_filter( 'woocommerce_add_to_cart_fragments', [ $this, 'add_add_to_cart_event_fragment' ] ); 215 } 216 } 217 218 219 /** 220 * Adds an add to cart fragment to trigger an AddToCart event. 221 * 222 * @internal 223 * 224 * @since 1.10.2 225 * 226 * @param array $fragments add to cart fragments 227 * @return array 228 */ 229 public function add_add_to_cart_event_fragment( $fragments ) { 230 231 if ( !empty(FacebookPixel::getPixelId()) ) { 232 233 $script = $this->pixel->get_event_script( 'AddToCart', [ 234 'content_ids' => $this->get_cart_content_ids(), 235 'content_type' => 'product', 236 'contents' => $this->get_cart_contents(), 237 'value' => $this->get_cart_total(), 238 'currency' => get_woocommerce_currency(), 239 ] ); 240 241 $fragments['div.wc-facebook-pixel-event-placeholder'] = '<div class="wc-facebook-pixel-event-placeholder">' . $script . '</div>'; 242 } 243 244 return $fragments; 245 } 246 247 /** 248 * Sets last product added to cart to session when adding to cart a product and redirection to cart is enabled. 249 * 250 * @internal 251 * 252 * @since 1.10.2 253 * 254 * @param string $redirect URL redirecting to (usually cart) 255 * @param null|\WC_Product $product the product just added to the cart 256 * @return string 257 */ 258 public function set_last_product_added_to_cart_upon_redirect( $redirect, $product = null ) { 259 260 if ( $product instanceof \WC_Product ) { 261 WC()->session->set( 'facebook_for_woocommerce_last_product_added_to_cart', $product->get_id() ); 262 } else { 263 264 } 265 266 return $redirect; 267 } 268 269 /** 209 270 * Triggers Purchase for thank you page for COD, BACS CHEQUE payment 210 271 * which won't invoke woocommerce_payment_complete. … … 213 274 { 214 275 if ( 215 (isset(self::$renderCache[0]) &&216 self::$renderCache[0] === true) ||217 276 empty(FacebookPixel::getPixelId()) 218 277 ) { … … 236 295 { 237 296 if ( 238 (isset(self::$renderCache[0]) &&239 self::$renderCache[0] === true) ||240 297 empty(FacebookPixel::getPixelId()) 241 298 ) { … … 277 334 { 278 335 if ( 279 (isset(self::$renderCache[0]) &&280 self::$renderCache[0] === true) ||281 336 empty(FacebookPixel::getPixelId()) 282 337 ) { … … 307 362 { 308 363 if ( 309 (isset(self::$renderCache[0]) &&310 self::$renderCache[0] === true) ||311 364 empty(FacebookPixel::getPixelId()) 312 365 ) { -
brainity-boost-ads/trunk/readme.txt
r2296756 r2309641 4 4 Requires at least: 5.2.1 5 5 Tested up to: 5.2.1 6 Stable tag: 1.0. 46 Stable tag: 1.0.5 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 65 65 == Changelog == 66 66 67 = Brainity 1.0. 4=67 = Brainity 1.0.5 = 68 68 69 69 * Fix bug with virtual products.
Note: See TracChangeset
for help on using the changeset viewer.