This commit is contained in:
2026-04-26 23:47:49 +02:00
parent 1b95f03d1e
commit b073e009d8
5288 changed files with 1112699 additions and 55536 deletions

View File

@@ -228,7 +228,12 @@ class ServerEventHelper {
if($order->get_billing_state()) {
$userData->setState($order->get_billing_state());
}
if($order->get_meta( 'external_id' )){
$external_id = $order->get_meta( 'external_id' );
if (!empty($external_id)) {
$userData->setExternalId($external_id);
}
}
} else {
if($order->billing_postcode) {
$userData->setZipCode($order->billing_postcode);
@@ -240,6 +245,12 @@ class ServerEventHelper {
$userData->setLastName($order->billing_last_name);
$userData->setCity($order->billing_city);
$userData->setState($order->billing_state);
if(get_post_meta( $order_id, 'external_id', true )){
$external_id = get_post_meta( $order_id, 'external_id', true );
if (!empty($external_id)) {
$userData->setExternalId($external_id);
}
}
}
} else {
return ServerEventHelper::getRegularUserData();
@@ -313,10 +324,18 @@ class ServerEventHelper {
$userData->setZipCode($user->get('billing_postcode'));
}
}
if(PixelYourSite\EventsManager::isTrackExternalId()){
if (isset($_COOKIE['pbid'])) {
$userData->setExternalId($_COOKIE['pbid']);
}
}
} else {
// $userData->setFirstName("undefined");
// $userData->setLastName("undefined");
// $userData->setEmail("undefined");
if (PixelYourSite\EventsManager::isTrackExternalId() && isset($_COOKIE['pbid'])) {
$userData->setExternalId($_COOKIE['pbid']);
}
}
return $userData;
}

View File

@@ -275,7 +275,11 @@ class FacebookServer {
$event->setEventId($event->getEventId());
$api = Api::init(null, null, $this->access_token[$pixel_Id],false);
$opts = $api->getHttpClient()->getAdapter()->getOpts();
if ($opts instanceof \ArrayObject && $opts->offsetExists(CURLOPT_CONNECTTIMEOUT)) {
$opts->offsetSet(CURLOPT_CONNECTTIMEOUT, 30);
$api->getHttpClient()->getAdapter()->setOpts($opts);
}
/**
* filter pys_before_send_fb_server_event
* Help add custom options or get data from event before send
@@ -310,9 +314,16 @@ class FacebookServer {
$pysData['fbc'] = ServerEventHelper::getFbc();
$pysData['fbp'] = ServerEventHelper::getFbp();
$order = wc_get_order($order_id);
if($order) {
$order->update_meta_data("pys_fb_cookie",$pysData);
$order->save();
if ( isWooCommerceVersionGte('3.0.0') ) {
// WooCommerce >= 3.0
if($order) {
$order->update_meta_data("pys_fb_cookie",$pysData);
$order->save();
}
} else {
// WooCommerce < 3.0
update_post_meta( $order_id, 'pys_fb_cookie', $pysData );
}
}

View File

@@ -43,6 +43,7 @@ class Facebook extends Settings implements Pixel {
add_action( 'pys_register_pixels', function( $core ) {
/** @var PYS $core */
$core->registerPixel( $this );
} );
add_action( 'wp_head', array( $this, 'output_meta_tag' ) );
@@ -76,7 +77,8 @@ class Facebook extends Settings implements Pixel {
if(count($ids) == 0|| empty($ids[0])) {
return apply_filters("pys_facebook_ids",[]);
} else {
return apply_filters("pys_facebook_ids",(array) reset( $ids )); // return first id only
$id = array_shift($ids);
return apply_filters("pys_facebook_ids", array($id)); // return first id only
}
}
@@ -85,16 +87,17 @@ class Facebook extends Settings implements Pixel {
return array(
'pixelIds' => $this->getPixelIDs(),
'advancedMatching' => $this->getOption( 'advanced_matching_enabled' ) ? Helpers\getAdvancedMatchingParams() : array(),
'removeMetadata' => $this->getOption( 'remove_metadata' ),
'advancedMatchingEnabled' => $this->getOption( 'advanced_matching_enabled' ),
'removeMetadata' => $this->getOption( 'remove_metadata' ),
'contentParams' => getTheContentParams(),
'commentEventEnabled' => $this->getOption( 'comment_event_enabled' ),
'wooVariableAsSimple' => $this->getOption( 'woo_variable_as_simple' ),
'downloadEnabled' => $this->getOption( 'download_event_enabled' ),
'formEventEnabled' => $this->getOption( 'form_event_enabled' ),
"ajaxForServerEvent" => $this->getOption( "server_event_use_ajax" ),
'serverApiEnabled' => $this->isServerApiEnabled() && count($this->getApiToken()) > 0,
'wooCRSendFromServer' => $this->getOption("woo_complete_registration_send_from_server") && $this->getOption("woo_complete_registration_fire_every_time")
);
'wooCRSendFromServer' => $this->getOption("woo_complete_registration_send_from_server") && $this->getOption("woo_complete_registration_fire_every_time"),
'send_external_id' => $this->getOption('send_external_id')
);
}
@@ -805,8 +808,21 @@ class Facebook extends Settings implements Pixel {
if ( ! $this->getOption( 'woo_purchase_enabled' ) ) {
return false;
}
$key = sanitize_key($_REQUEST['key']);
$order_id = (int) wc_get_order_id_by_order_key( $key );
$order_key = sanitize_key($_REQUEST['key']);
$cache_key = 'order_id_' . $order_key;
$order_id = get_transient( $cache_key );
global $wp;
if (is_order_received_page() && empty($order_id) && $wp->query_vars['order-received']) {
$order_id = absint( $wp->query_vars['order-received'] );
if ($order_id) {
set_transient( $cache_key, $order_id, HOUR_IN_SECONDS );
}
}
if ( empty($order_id) ) {
$order_id = (int) wc_get_order_id_by_order_key( $order_key );
set_transient( $cache_key, $order_id, HOUR_IN_SECONDS );
}
$order = new \WC_Order( $order_id );
$content_ids = array();
@@ -874,6 +890,10 @@ class Facebook extends Settings implements Pixel {
$params['currency'] = get_woocommerce_currency();
$params['order_id'] = $order_id;
$params['fees'] = get_fees($order);
return array(
'name' => 'Purchase',
'data' => $params,
@@ -982,17 +1002,17 @@ class Facebook extends Settings implements Pixel {
$params = array(
'content_type' => 'product',
'content_ids' => Helpers\getFacebookEddDownloadContentId( $post->ID ),
'content_ids' => Helpers\getFacebookEddDownloadContentId( $download_id ),
);
// content_name, category_name
$params['tags'] = implode( ', ', getObjectTerms( 'download_tag', $post->ID ) );
$params = array_merge( $params, Helpers\getEddCustomAudiencesOptimizationParams( $post->ID ) );
$params['tags'] = implode( ', ', getObjectTerms( 'download_tag', $download_id ) );
$params = array_merge( $params, Helpers\getEddCustomAudiencesOptimizationParams( $download_id ) );
// currency, value
if ( PYS()->getOption( 'edd_add_to_cart_value_enabled' ) ) {
$amount = getEddDownloadPriceToDisplay( $post->ID, $price_index );
$amount = getEddDownloadPriceToDisplay( $download_id, $price_index );
$value_option = PYS()->getOption( 'edd_add_to_cart_value_option' );
$global_value = PYS()->getOption( 'edd_add_to_cart_value_global', 0 );

View File

@@ -52,8 +52,21 @@ function getAdvancedMatchingParams() {
*/
if ( is_order_received_page() && isset( $_REQUEST['key'] ) && $_REQUEST['key'] != "" ) {
$key = sanitize_key($_REQUEST['key']);
$order_id = wc_get_order_id_by_order_key($key );
$order_key = sanitize_key($_REQUEST['key']);
$cache_key = 'order_id_' . $order_key;
$order_id = get_transient( $cache_key );
global $wp;
if (empty($order_id) && $wp->query_vars['order-received']) {
$order_id = absint( $wp->query_vars['order-received'] );
if ($order_id) {
set_transient( $cache_key, $order_id, HOUR_IN_SECONDS );
}
}
if ( empty($order_id) ) {
$order_id = (int) wc_get_order_id_by_order_key( $order_key );
set_transient( $cache_key, $order_id, HOUR_IN_SECONDS );
}
$order = wc_get_order( $order_id );
if ( $order ) {
@@ -141,7 +154,11 @@ function getAdvancedMatchingParams() {
}
}
if(PixelYourSite\EventsManager::isTrackExternalId()){
if (isset($_COOKIE['pbid'])) {
$params['external_id'] = $_COOKIE['pbid'];
}
}
$sanitized = array();
foreach ( $params as $key => $value ) {
@@ -572,7 +589,12 @@ function getFDPPurchaseEventParams() {
function getCompleteRegistrationOrderParams() {
$params = array();
$order_key = sanitize_key( $_REQUEST['key']);
$order_id = (int) wc_get_order_id_by_order_key( $order_key );
$cache_key = 'order_id_' . $order_key;
$order_id = get_transient( $cache_key );
if ( empty($order_id) ) {
$order_id = (int) wc_get_order_id_by_order_key( $order_key );
set_transient( $cache_key, $order_id, HOUR_IN_SECONDS );
}
$order = new \WC_Order( $order_id );
$value_option = PixelYourSite\Facebook()->getOption( 'woo_complete_registration_custom_value' );

View File

@@ -49,7 +49,6 @@
"fdp_purchase_value" : "0",
"use_server_api": false,
"server_event_use_ajax": true,
"server_access_api_token": "",
"test_api_event_code": "",
"test_api_event_code_expiration_at": "",

View File

@@ -48,7 +48,6 @@
"fdp_purchase_value" : "text",
"use_server_api": "checkbox",
"server_event_use_ajax": "checkbox",
"server_access_api_token": "array",
"test_api_event_code": "array",
"test_api_event_code_expiration_at": "array",

View File

@@ -29,8 +29,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="alert alert-primary mt-3">Because of a Facebook error, when Advanced Matching is ON, Custom
Audiences based on the pixel
will not show the size number ("Size: -1", or "Size Unavailable"). They will still work fine for
retargeting or Lookalike Audiences. Details <a href="https://www.pixelyoursite
.com/facebook-audience-size-not-available" target="_blank">here</a>.</div>
retargeting or Lookalike Audiences. Details <a href="https://www.pixelyoursite.com/facebook-audience-size-not-available" target="_blank">here</a>.</div>
</div>
</div>
<div class="row">

View File

@@ -69,6 +69,15 @@ class GA extends Settings implements Pixel {
$flags = (array) $this->getOption( 'is_enable_debug_mode' );
if ( isSuperPackActive() && SuperPack()->getOption( 'enabled' ) && SuperPack()->getOption( 'additional_ids_enabled' ) ) {
$additionalPixels = SuperPack()->getGaAdditionalPixel();
$index = 1;
foreach ($additionalPixels as $_pixel) {
if($_pixel->extensions['debug_mode'])
{
$flags[] = 'index_'.$index;
}
$index++;
}
return $flags;
} else {
return (array) reset( $flags ); // return first id only
@@ -81,7 +90,8 @@ class GA extends Settings implements Pixel {
if(count($ids) == 0) {
return apply_filters("pys_ga_ids",[]);
} else {
return apply_filters("pys_ga_ids",(array) reset( $ids )); // return first id only
$id = array_shift($ids);
return apply_filters("pys_ga_ids", array($id)); // return first id only
}
}
@@ -106,6 +116,9 @@ class GA extends Settings implements Pixel {
'wooVariableAsSimple' => $this->getOption( 'woo_variable_as_simple' )
);
}
private function isGaV4($tag) {
return strpos($tag, 'G') === 0;
}
/**
* Create pixel event and fill it
* @param SingleEvent $event
@@ -117,7 +130,18 @@ class GA extends Settings implements Pixel {
return [];
}
$pixelIds = $this->getPixelIDs();
$onlyGA4event = ['woo_view_cart'];
$isGA4Event = in_array($event->getId(), $onlyGA4event);
$pixelIds = array();
if($isGA4Event)
{
if($this->isGaV4($this->getPixelIDs()[0])){
$pixelIds = $this->getPixelIDs();
}
}
else{
$pixelIds = $this->getPixelIDs();
}
if(count($pixelIds) > 0) {
$pixelEvent = clone $event;
@@ -199,6 +223,9 @@ class GA extends Settings implements Pixel {
$this->addDataToEvent($eventData, $event);
}
}break;
case 'woo_view_cart': {
$isActive = $this->getWooViewCartEventParams($event);
}break;
case 'woo_add_to_cart_on_cart_page':
case 'woo_add_to_cart_on_checkout_page':{
$eventData = $this->getWooAddToCartOnCartEventParams();
@@ -225,14 +252,14 @@ class GA extends Settings implements Pixel {
$this->addDataToEvent($eventData, $event);
}
}break;
case 'woo_view_item_list':
/*case 'woo_view_item_list':
{
$eventData = $this->getWooViewCategoryEventParams();
if ($eventData) {
$isActive = true;
$this->addDataToEvent($eventData, $event);
}
}break;
}break;*/
case 'edd_view_content': {
$eventData = $this->getEddViewContentEventParams();
if ($eventData) {
@@ -255,13 +282,13 @@ class GA extends Settings implements Pixel {
}
}break;
case 'edd_view_category': {
/*case 'edd_view_category': {
$eventData = $this->getEddViewCategoryEventParams();
if ($eventData) {
$isActive = true;
$this->addDataToEvent($eventData, $event);
}
}break;
}break;*/
case 'edd_initiate_checkout': {
$eventData = $this->getEddCartEventParams('begin_checkout');
@@ -467,7 +494,6 @@ class GA extends Settings implements Pixel {
}
}
$list_name = implode( '/', array_reverse( $product_categories ) );
$items = array();
$product_ids = array();
@@ -482,13 +508,14 @@ class GA extends Settings implements Pixel {
$item = array(
'id' => GA\Helpers\getWooProductContentId($posts[ $i ]->ID),
'name' => $posts[ $i ]->post_title,
'category' => implode( '/', getObjectTerms( 'product_cat', $posts[ $i ]->ID ) ),
'quantity' => 1,
'price' => getWooProductPriceToDisplay( $posts[ $i ]->ID ),
'list_position' => $i + 1,
'list' => $list_name,
);
$category = $this->getCategoryArrayWoo($posts[ $i ]->ID);
if(!empty($category))
{
$item = array_merge($item, $category);
}
$items[] = $item;
$product_ids[] = $item['id'];
$total_value += $item['price'];
@@ -497,7 +524,7 @@ class GA extends Settings implements Pixel {
$params = array(
'event_category' => 'ecommerce',
'event_label' => $list_name,
'event_label' => 'category',
'items' => $items,
'non_interaction' => $this->getOption( 'woo_view_category_non_interactive' ),
);
@@ -510,25 +537,59 @@ class GA extends Settings implements Pixel {
}
private function getWooViewContentEventParams() {
global $post;
if ( ! $this->getOption( 'woo_view_content_enabled' ) ) {
return false;
}
$quantity = 1;
$customProductPrice = -1;
global $post;
$product = wc_get_product( $post->ID );
if(!$product) return false;
$productId = GA\Helpers\getWooProductContentId($product->get_id());
$items = array();
$general_item = array(
'id' => $productId,
'name' => $product->get_name(),
'quantity' => $quantity,
'price' => getWooProductPriceToDisplay($product->get_id(), $quantity, $customProductPrice),
);
$category = $this->getCategoryArrayWoo($productId);
if(!empty($category))
{
$general_item = array_merge($general_item, $category);
}
$items[] = $general_item;
// Check if the product has variations
if ($product->is_type('variable') && !$this->getOption( 'woo_variable_as_simple' )) {
$variations = $product->get_available_variations();
foreach ($variations as $variation) {
$variationProduct = wc_get_product($variation['variation_id']);
$variationProductId = GA\Helpers\getWooProductContentId($variation['variation_id']);
$category = $this->getCategoryArrayWoo($variationProductId, true);
$item = array(
'id' => $variationProductId,
'name' => $this->getOption('woo_variations_use_parent_name') ? $variationProduct->get_title() : $variationProduct->get_name(),
'quantity' => $quantity,
'price' => getWooProductPriceToDisplay($variationProduct->get_id(), $quantity, $customProductPrice)
);
$items[] = array_merge($item, $category);
}
}
$params = array(
'event_category' => 'ecommerce',
'non_interaction' => $this->getOption( 'woo_view_content_non_interactive' ),
);
$params['items'] = $items;
$params = array(
'event_category' => 'ecommerce',
'items' => array(
array(
'id' => GA\Helpers\getWooProductContentId($post->ID),
'name' => $post->post_title,
'category' => implode( '/', getObjectTerms( 'product_cat', $post->ID ) ),
'quantity' => 1,
'price' => getWooProductPriceToDisplay( $post->ID ),
),
),
'non_interaction' => $this->getOption( 'woo_view_content_non_interactive' ),
);
return array(
'name' => 'view_item',
@@ -537,7 +598,72 @@ class GA extends Settings implements Pixel {
);
}
private function getWooViewCartEventParams(&$event){
if ( ! $this->getOption( 'woo_view_cart_enabled' ) ) {
return false;
}
$data = ['name' => 'view_cart'];
$payload = $event->payload;
$params = $this->getWooEventViewCartParams( $event );
$event->addParams($params);
$event->addPayload($data);
return true;
}
private function getWooEventViewCartParams($event){
$params = [
'event_category' => 'ecommerce',
];
$params['currency'] = get_woocommerce_currency();
$items = array();
$product_ids = array();
$withTax = 'incl' === get_option( 'woocommerce_tax_display_cart' );
if(WC()->cart->get_cart())
{
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
$product = wc_get_product(!empty($cart_item['variation_id']) ? $cart_item['variation_id'] : $cart_item['product_id']);
if ($product) {
$product_data = $product->get_data();
$product_id = GA\Helpers\getWooCartItemId( $cart_item );
$content_id = GA\Helpers\getWooProductContentId($product_id);
$price = $cart_item['line_subtotal'];
if ($withTax) {
$price += $cart_item['line_subtotal_tax'];
}
$item = array(
'id' => $content_id,
'name' => $this->getOption('woo_variations_use_parent_name') && $product->is_type('variation') ? $product->get_title() : $product->get_name(),
'quantity' => $cart_item['quantity'],
'price' => $cart_item['quantity'] > 0 ? pys_round($price / $cart_item['quantity']) : $price,
);
$category = $this->getCategoryArrayWoo($product_id, $product->is_type('variation'));
if (!empty($category)) {
$item = array_merge($item, $category);
}
if ($product && $product->is_type('variation')) {
foreach ($event->args['products'] as $event_product){
if($event_product['product_id'] == $product_id && !empty($event_product['variation_name']))
{
$item['variant'] = $event_product['variation_name'];
}
}
}
$items[] = $item;
$product_ids[] = $item['id'];
}
}
}
$params['items'] = $items;
$params['value'] = getWooEventCartTotal($event);
return $params;
}
private function getWooAddToCartOnButtonClickEventParams( $args ) {
if ( ! $this->getOption( 'woo_add_to_cart_enabled' ) || ! PYS()->getOption( 'woo_add_to_cart_on_button_click' ) ) {
@@ -566,23 +692,28 @@ class GA extends Settings implements Pixel {
}
$content_id = GA\Helpers\getWooProductContentId($child_id);
$price = getWooProductPriceToDisplay( $child_id, $quantity );
$name = $childProduct->get_title();
$name = $this->getOption('woo_variations_use_parent_name') && $childProduct->is_type('variation') ? $childProduct->get_title() : $childProduct->get_name();
if ( $childProduct->get_type() == 'variation' ) {
$variation_name = implode("/", $childProduct->get_variation_attributes());
$categories = implode( '/', getObjectTerms( 'product_cat', $childProduct->get_parent_id() ) );
$variation_name = !$this->getOption('woo_variations_use_parent_name') ? implode("/", $childProduct->get_variation_attributes()) : $product->get_title();
$categories = $this->getCategoryArrayWoo($child_id, true);
} else {
$categories = implode( '/', getObjectTerms( 'product_cat', $child_id ) );
$categories = $this->getCategoryArrayWoo($child_id);
$variation_name = null;
}
$items[] = array(
$item = array(
'id' => $content_id,
'name' => $name,
'category' => $categories,
'quantity' => $quantity,
'price' => $price,
'variant' => $variation_name,
);
if (!empty($categories)) {
$item = array_merge($item, $categories);
}
$items[] = $item;
}
@@ -644,18 +775,19 @@ class GA extends Settings implements Pixel {
$name = $product->get_title();
if ( ! empty( $cart_item['variation_id'] ) ) {
$variation = wc_get_product( (int) $cart_item['variation_id'] );
if($variation && $variation->get_type() == 'variation') {
$variation_name = implode("/", $variation->get_variation_attributes());
$categories = implode( '/', getObjectTerms( 'product_cat', $variation->get_parent_id() ) );
$variation = wc_get_product( $cart_item['variation_id'] );
if($variation && $variation->get_type() == 'variation' && !$this->getOption( 'woo_variable_as_simple' )) {
$variation_name = !$this->getOption('woo_variations_use_parent_name') ? implode("/", $variation->get_variation_attributes()) : $product->get_title();
$categories = $this->getCategoryArrayWoo($product_id, true);
} else {
$variation_name = null;
$categories = implode( '/', getObjectTerms( 'product_cat', $product_id ) );
$categories = $this->getCategoryArrayWoo($product_id);
}
} else {
$variation_name = null;
$categories = implode( '/', getObjectTerms( 'product_cat', $product_id ) );
$categories = $this->getCategoryArrayWoo($product_id);
}
$data = [
@@ -668,13 +800,18 @@ class GA extends Settings implements Pixel {
array(
'id' => $product_id,
'name' => $name,
'category' => $categories,
'quantity' => $cart_item['quantity'],
'price' => getWooProductPriceToDisplay( $product_id, $cart_item['quantity'] ),
'variant' => $variation_name,
),
),
'non_interaction' => $this->getOption( 'woo_remove_from_cart_non_interactive' ),];
if(!empty($categories))
{
$params['items'][0] = array_merge($params['items'][0], $categories);
}
$event->addParams($params);
$event->addPayload($data);
@@ -698,12 +835,24 @@ class GA extends Settings implements Pixel {
}
private function getWooPurchaseEventParams() {
global $wp;
if ( ! $this->getOption( 'woo_purchase_enabled' ) ) {
return false;
}
$key = sanitize_key($_REQUEST['key']);
$order_id = (int) wc_get_order_id_by_order_key( $key );
$cache_key = 'order_id_' . $key;
$order_id = get_transient( $cache_key );
if (is_order_received_page() && empty($order_id) && $wp->query_vars['order-received']) {
$order_id = absint( $wp->query_vars['order-received'] );
if ($order_id) {
set_transient( $cache_key, $order_id, HOUR_IN_SECONDS );
}
}
if ( empty($order_id) ) {
$order_id = (int) wc_get_order_id_by_order_key( $key );
set_transient( $cache_key, $order_id, HOUR_IN_SECONDS );
}
$order = new \WC_Order( $order_id );
$items = array();
@@ -717,20 +866,23 @@ class GA extends Settings implements Pixel {
$product = wc_get_product( $product_id );
if(!$product) continue;
$name = $product->get_title();
$name = $this->getOption('woo_variations_use_parent_name') && $product->is_type('variation') ? $product->get_title() : $product->get_name();
if ( $line_item['variation_id'] ) {
if ( $line_item['variation_id'] ) {
$variation = wc_get_product( $line_item['variation_id'] );
if($variation && $variation->get_type() == 'variation') {
$variation_name = implode("/", $variation->get_variation_attributes());
$categories = implode( '/', getObjectTerms( 'product_cat', $variation->get_parent_id() ) );
if($variation && $variation->get_type() == 'variation' && !$this->getOption( 'woo_variable_as_simple' )) {
$variation_name = !$this->getOption('woo_variations_use_parent_name') ? implode("/", $variation->get_variation_attributes()) : $product->get_title();
$categories = $this->getCategoryArrayWoo($product_id, true);
} else {
$variation_name = null;
$categories = implode( '/', getObjectTerms( 'product_cat', $product_id ) );
$categories = $this->getCategoryArrayWoo($product_id);
}
} else {
$variation_name = null;
$categories = implode( '/', getObjectTerms( 'product_cat', $product_id ) );
$categories = $this->getCategoryArrayWoo($product_id);
}
/**
@@ -767,12 +919,13 @@ class GA extends Settings implements Pixel {
$item = array(
'id' => $content_id,
'name' => $name,
'category' => $categories,
'quantity' => $qty,
'price' => $price,
'variant' => $variation_name,
);
if (!empty($categories)) {
$item = array_merge($item, $categories);
}
$items[] = $item;
$product_ids[] = $item['id'];
$total_value += $item['price' ];
@@ -788,6 +941,8 @@ class GA extends Settings implements Pixel {
'non_interaction' => $this->getOption( 'woo_purchase_non_interactive' ),
);
$params['fees'] = get_fees($order);
return array(
'name' => 'purchase',
'data' => $params
@@ -809,31 +964,36 @@ class GA extends Settings implements Pixel {
$product = wc_get_product( $product_id );
if(!$product) continue;
$name = $product->get_title();
$name = $this->getOption('woo_variations_use_parent_name') && $product->is_type('variation') ? $product->get_title() : $product->get_name();
if ( $cart_item['variation_id'] ) {
$variation = wc_get_product( $cart_item['variation_id'] );
if ( $variation && $variation->get_type() == 'variation' ) {
$variation_name = implode("/", $variation->get_variation_attributes());
$categories = implode( '/', getObjectTerms( 'product_cat', $variation->get_parent_id() ) );
$variation = wc_get_product( $cart_item['variation_id'] );
if($variation && $variation->get_type() == 'variation' && !$this->getOption( 'woo_variable_as_simple' )) {
$variation_name = !$this->getOption('woo_variations_use_parent_name') ? implode("/", $variation->get_variation_attributes()) : $product->get_title();
$categories = $this->getCategoryArrayWoo($product_id, true);
} else {
$variation_name = null;
$categories = implode( '/', getObjectTerms( 'product_cat', $product_id ) );
$categories = $this->getCategoryArrayWoo($product_id);
}
} else {
$variation_name = null;
$categories = implode( '/', getObjectTerms( 'product_cat', $product_id ) );
} else {
$variation_name = null;
$categories = $this->getCategoryArrayWoo($product_id);
}
$item = array(
'id' => $content_id,
'name' => $name,
'category' => $categories,
'quantity' => $cart_item['quantity'],
'price' => getWooProductPriceToDisplay( $product_id ),
'variant' => $variation_name,
);
if (!empty($categories)) {
$item = array_merge($item, $categories);
}
$items[] = $item;
$product_ids[] = $item['id'];
$total_value += $item['price'];
@@ -1095,6 +1255,30 @@ class GA extends Settings implements Pixel {
}
private function getCategoryArrayWoo($contentID, $isVariant = false)
{
$category_array = array();
if ($isVariant) {
$parent_product_id = wp_get_post_parent_id($contentID);
$category = getObjectTerms('product_cat', $parent_product_id);
} else {
$category = getObjectTerms('product_cat', $contentID);
}
$category_index = 1;
foreach ($category as $cat) {
if ($category_index >= 6) {
break; // Stop the loop if the maximum limit of 5 categories is exceeded
}
$category_array['item_category' . ($category_index > 1 ? $category_index : '')] = $cat;
$category_index++;
}
return $category_array;
}
}
/**

View File

@@ -18,6 +18,7 @@
"form_event_non_interactive": false,
"woo_variable_as_simple": false,
"woo_variations_use_parent_name": false,
"woo_content_id": "product_id",
"woo_content_id_prefix": "",
"woo_content_id_suffix": "",
@@ -34,6 +35,7 @@
"woo_view_content_non_interactive": true,
"woo_view_category_enabled": true,
"woo_view_category_non_interactive": true,
"woo_view_cart_enabled" : true,
"edd_content_id": "download_id",
"edd_content_id_prefix": "",

View File

@@ -18,6 +18,7 @@
"form_event_non_interactive": "checkbox",
"woo_variable_as_simple": "checkbox",
"woo_variations_use_parent_name": "checkbox",
"woo_content_id": "select",
"woo_content_id_prefix": "text",
"woo_content_id_suffix": "text",
@@ -34,6 +35,7 @@
"woo_view_content_non_interactive": "checkbox",
"woo_view_category_enabled": "checkbox",
"woo_view_category_non_interactive": "checkbox",
"woo_view_cart_enabled" : "checkbox",
"edd_content_id": "select",
"edd_content_id_prefix": "text",

View File

@@ -35,7 +35,7 @@ class HeadFooter extends Settings {
/** @var PYS $core */
$core->registerPlugin( $this );
} );
if ( $this->getOption( 'enabled' ) ) {
add_action( 'add_meta_boxes', array( $this, 'register_meta_box' ) );
add_action( 'save_post', array( $this, 'save_meta_box' ) );
@@ -52,7 +52,7 @@ class HeadFooter extends Settings {
*/
public function register_meta_box() {
if ( current_user_can( 'manage_pys' ) ) {
if ( current_user_can( 'manage_pys' ) && current_user_can('unfiltered_html') ) {
$screens = get_post_types( array( 'public' => true ) );
@@ -76,7 +76,7 @@ class HeadFooter extends Settings {
return;
}
if ( ! current_user_can( 'manage_pys' ) ) {
if ( ! current_user_can( 'manage_pys' ) && ! current_user_can('unfiltered_html')) {
return;
}
@@ -86,16 +86,31 @@ class HeadFooter extends Settings {
}
$data = $_POST['pys_head_footer'];
$meta = array(
'disable_global' => isset( $data['disable_global'] ) ? true : false,
'head_any' => isset( $data['head_any'] ) ? trim( $data['head_any'] ) : '',
'head_desktop' => isset( $data['head_desktop'] ) ? trim( $data['head_desktop'] ) : '',
'head_mobile' => isset( $data['head_mobile'] ) ? trim( $data['head_mobile'] ) : '',
'footer_any' => isset( $data['footer_any'] ) ? trim( $data['footer_any'] ) : '',
'footer_desktop' => isset( $data['footer_desktop'] ) ? trim( $data['footer_desktop'] ) : '',
'footer_mobile' => isset( $data['footer_mobile'] ) ? trim( $data['footer_mobile'] ) : '',
);
$meta = array(
'disable_global' => isset( $data['disable_global'] ) ? true : false,
);
foreach ( $data as $key => $val ) {
switch ($key) {
case "head_any":
$meta['head_any'] = isset($val) ? trim($val) : '';
break;
case "head_desktop":
$meta['head_desktop'] = isset($val) ? trim($val) : '';
break;
case "head_mobile":
$meta['head_mobile'] = isset($val) ? trim($val) : '';
break;
case "footer_any":
$meta['footer_any'] = isset($val) ? trim($val) : '';
break;
case "footer_desktop":
$meta['footer_desktop'] = isset($val) ? trim($val) : '';
break;
case "footer_mobile":
$meta['footer_mobile'] = isset($val) ? trim($val) : '';
break;
}
}
update_post_meta( $post_id, '_pys_head_footer', $meta );
@@ -156,7 +171,7 @@ class HeadFooter extends Settings {
public function output_head_woo_order_received() {
$scripts_any = $this->getOption( 'woo_order_received_head_any' );
$scripts_any = esc_js($this->getOption( 'woo_order_received_head_any' ));
if ( $scripts_any ) {
echo "\r\n{$scripts_any}\r\n";

View File

@@ -0,0 +1,180 @@
<?php
namespace PixelYourSite;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
?>
<h2 class="section-title">Head and Footer Settings</h2>
<!-- General -->
<div class="card card-static">
<div class="card-header">
General
</div>
<div class="card-body">
<div class="row">
<div class="col">
<p>
Your user role doesn't have permission to add this type of code. You need unfiltered_html capabilities. Ask your admin to upgrade your account. For Multisite, ask your super admin to upgrade your account.
</p>
</div>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col">
<?php renderDummySwitcher( 'false' ); ?>
<h4 class="switcher-label">Enable Head and Footer</h4>
</div>
</div>
</div>
</div>
<!-- Header Scripts -->
<div class="card card-static">
<div class="card-header">
Head Scripts
</div>
<div class="card-body">
<div class="row form-group">
<div class="col">
<h4 class="label">Any device type:</h4>
<?php renderDummyTextAreaInput( 'head_any' ); ?>
</div>
</div>
<div class="row form-group">
<div class="col">
<h4 class="label">Desktop Only:</h4>
<?php renderDummyTextAreaInput( 'head_desktop' ); ?>
</div>
</div>
<div class="row">
<div class="col">
<h4 class="label">Mobile Only:</h4>
<?php renderDummyTextAreaInput( 'head_mobile' ); ?>
</div>
</div>
</div>
</div>
<!-- Footer Scripts -->
<div class="card card-static">
<div class="card-header">
Footer Scripts
</div>
<div class="card-body">
<div class="row form-group">
<div class="col">
<h4 class="label">Any device type:</h4>
<?php renderDummyTextAreaInput( 'footer_any' ); ?>
</div>
</div>
<div class="row form-group">
<div class="col">
<h4 class="label">Desktop Only:</h4>
<?php renderDummyTextAreaInput( 'footer_desktop' ); ?>
</div>
</div>
<div class="row">
<div class="col">
<h4 class="label">Mobile Only:</h4>
<?php renderDummyTextAreaInput( 'footer_mobile' ); ?>
</div>
</div>
</div>
</div>
<?php if( isWooCommerceActive() ) : ?>
<h2 class="section-title">WooCommerce Order Received Page Scripts</h2>
<!-- <p>Insert any script on the WooCommerce Thank You Page (order-received).</p>-->
<div class="card card-static">
<div class="card-header">
General
</div>
<div class="card-body">
<div class="row">
<div class="col">
<?php renderDummySwitcher( false ); ?>
<h4 class="switcher-label">Disable global head and footer scripts on Order Received page</h4>
</div>
</div>
</div>
</div>
<div class="card card-static">
<div class="card-header">
Head Scripts
</div>
<div class="card-body">
<div class="row form-group">
<div class="col">
<h4 class="label">Any device type:</h4>
<?php renderDummyTextAreaInput( 'woo_order_received_head_any' ); ?>
</div>
</div>
<div class="row form-group">
<div class="col">
<h4 class="label">Desktop Only:</h4>
<?php renderDummyTextAreaInput( 'woo_order_received_head_desktop' ); ?>
</div>
</div>
<div class="row">
<div class="col">
<h4 class="label">Mobile Only:</h4>
<?php renderDummyTextAreaInput( 'woo_order_received_head_mobile' ); ?>
</div>
</div>
</div>
</div>
<div class="card card-static">
<div class="card-header">
Footer Scripts
</div>
<div class="card-body">
<div class="row form-group">
<div class="col">
<h4 class="label">Any device type:</h4>
<?php renderDummyTextAreaInput( 'woo_order_received_footer_any' ); ?>
</div>
</div>
<div class="row form-group">
<div class="col">
<h4 class="label">Desktop Only:</h4>
<?php renderDummyTextAreaInput( 'woo_order_received_footer_desktop' ); ?>
</div>
</div>
<div class="row">
<div class="col">
<h4 class="label">Mobile Only:</h4>
<?php renderDummyTextAreaInput( 'woo_order_received_footer_mobile' ); ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
<h2 class="section-title">Replacements <?php renderHfBadge(); ?></h2>
<div class="panel">
<div class="row">
<div class="col text-secondary">
<?php include 'html-variables-help.php'; ?>
</div>
</div>
</div>
<hr>
<div class="row justify-content-center">
<div class="col-4">
<button class="btn btn-block btn-save">Save Settings</button>
</div>
</div>

View File

@@ -140,7 +140,27 @@ if ( ! defined( 'ABSPATH' ) ) {
<?php endif; ?>
</div>
</div>
<!-- Hide this tag -->
<div class="card card-static">
<div class="card-header">
Hide tag <?php renderSpBadge(); ?>
</div>
<div class="card-body">
<div class="row">
<div class="col">
<?php renderDummySwitcher(); ?>
<h4 class="switcher-label">Hide this tag if the landing URL includes these URL tags</h4>
</div>
</div>
<div class="row">
<div class="col">
<?php renderDummySwitcher(); ?>
<h4 class="switcher-label">Hide this tag if the URL includes</h4>
</div>
</div>
</div>
</div>
<!-- Remove Pixel -->
<div class="card card-static">
<div class="card-header">