Changeset 2309723
- Timestamp:
- 05/21/2020 08:21:22 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
brainity-boost-ads/trunk/pixel/FacebookWordpressPixelInjection.php
r2309641 r2309723 9 9 const FB_PRIORITY_LOW = 11; 10 10 const FB_RETAILER_ID_PREFIX = 'wc_post_id_'; 11 public $isviewcontentRender = 0; 11 12 12 13 public function __construct() … … 83 84 public function inject_view_content_event() 84 85 { 85 global $post;86 if (87 empty(FacebookPixel::getPixelId() || !isset($post->ID))88 ) {89 return;90 }91 86 92 $product = wc_get_product($post->ID); 93 $content_type = 'product_group'; 94 if (!$product) { 95 return; 96 } 97 98 // if product is a variant, fire the pixel with content_type: product_group 99 if (self::is_variation_type($product->get_type())) { 87 global $post; 88 if ( empty(FacebookPixel::getPixelId() || !isset($post->ID)) ) { 89 return; 90 } 91 $product = wc_get_product( $post->ID ); 92 if ( ! $product instanceof \WC_Product ) { 93 return; 94 } 95 96 // if product is variable or grouped, fire the pixel with content_type: product_group 97 if ( $product->is_type( [ 'variable', 'grouped' ] ) ) { 98 $content_type = 'product_group'; 99 } else { 100 100 $content_type = 'product'; 101 101 } 102 102 103 103 $content_ids = self::get_fb_content_ids($product); 104 FacebookPixel::inject_event( 105 'ViewContent', 106 array( 107 'content_name' => $product->get_title(), 108 'content_ids' => json_encode($content_ids), 109 'content_type' => $content_type, 110 'value' => $product->get_price(), 111 'currency' => get_woocommerce_currency() 112 )); 104 if($this->isviewcontentRender == wp_json_encode($content_ids)) { 105 return; 106 } 107 $this->isviewcontentRender = wp_json_encode($content_ids); 108 $this->pixel->inject_event( 'ViewContent', [ 109 'content_name' => $product->get_title(), 110 'content_ids' => $this->isviewcontentRender, 111 'content_type' => $content_type, 112 'value' => $product->get_price(), 113 'currency' => get_woocommerce_currency(), 114 ] ); 115 113 116 } 114 117 … … 172 175 return; 173 176 } 177 178 $last_product_id = WC()->session->get( 'facebook_for_woocommerce_last_product_added_to_cart', 0 ); 179 174 180 $redirect_checked = get_option('woocommerce_cart_redirect_after_add', 'no'); 175 if ($redirect_checked == 'yes' ) {181 if ($redirect_checked == 'yes' && $last_product_id > 0) { 176 182 $this->inject_add_to_cart_event(); 183 WC()->session->set( 'facebook_for_woocommerce_last_product_added_to_cart', 0 ); 177 184 } 178 185 } … … 243 250 244 251 return $fragments; 252 } 253 254 /** 255 * Sets last product added to cart to session when adding a product to cart from an archive page and both AJAX adding and redirection to cart are enabled. 256 * 257 * @internal 258 * 259 * @since 1.10.2 260 * 261 * @param null|int $product_id the ID of the product just added to the cart 262 */ 263 public function set_last_product_added_to_cart_upon_ajax_redirect( $product_id = null ) { 264 if ( ! $product_id ) { 265 return; 266 } 267 $product = wc_get_product( $product_id ); 268 if ( $product instanceof \WC_Product ) { 269 WC()->session->set( 'facebook_for_woocommerce_last_product_added_to_cart', $product->get_id() ); 270 } 245 271 } 246 272
Note: See TracChangeset
for help on using the changeset viewer.