term_id, $categories)) { $categories[$productTerm->term_id] = array( 'name' => $productTerm->name, 'counter' => 1 ); } else { $categories[$productTerm->term_id]['counter']++; } } } } $categoryCounter = 0; $categoryId = 0; $categoryName = ''; foreach($categories as $id => $category) { if($category['counter'] > $categoryCounter) { $categoryId = $id; $categoryName = rawurlencode($category['name']); $categoryCounter = $category['counter']; } } $productRefs = RoleWcAdcellFeed::product_refs(array_map('wc_get_product', $productIds)); if(is_search()) { $params = '&search=' . rawurlencode(get_search_query(false)); $method = 'search'; } else { $params = '&categoryName=' . $categoryName . '&categoryId=' . $categoryId; $method = 'category'; } RoleWcAdcell::footer_script(roleWcAdcellRetargetingUrl($method, $params . '&productIds=' . $productRefs . '&productSeparator=;&faktor=2')); } function roleWcAdcellTrackingProductRetargeting() { global $product; if (!$product instanceof WC_Product) { return; } $related = RoleWcAdcellFeed::product_refs(array_map('wc_get_product', wc_get_related_products($product->get_id(), 20))); $categoryIds = $product->get_category_ids(); $categoryId = ! empty( $categoryIds ) ? $categoryIds[0] : 0; RoleWcAdcell::footer_script(roleWcAdcellRetargetingUrl('product', '&productId=' . rawurlencode(RoleWcAdcellFeed::product_ref($product)) . '&productName=' . rawurlencode($product->get_name()) . '&categoryId=' . $categoryId . '&productIds=' . $related . '&productSeparator=;&faktor=2')); } function roleWcAdcellTrackingCartRetargeting() { if (!function_exists('WC') || !WC()->cart || WC()->cart->is_empty()) { return; } if (!is_cart() && !(is_checkout() && !is_wc_endpoint_url('order-received'))) { return; } $cartProducts = array(); $cartQuantities = array(); $cartCount = 0; $cartAmount = 0.0; foreach(WC()->cart->get_cart() as $values) { $cartProducts[] = $values['data']; $cartQuantities[] = $values['quantity']; $cartCount += $values['quantity']; $cartAmount += (float) $values['line_total']; } RoleWcAdcell::footer_script(roleWcAdcellRetargetingUrl('basket', '&productIds=' . RoleWcAdcellFeed::product_refs($cartProducts) . '&productSeparator=;&quantities=' . implode(';', $cartQuantities) . '&basketProductCount=' . $cartCount . '&basketTotal=' . number_format($cartAmount, 2, '.', '') . '&faktor=2')); } function roleWcAdcellTrackingOrderRetargeting($wcOrder) { $orderProducts = array(); $orderQuantities = array(); $orderCount = 0; foreach($wcOrder->get_items() as $item) { $product = $item->get_product(); $orderProducts[] = rawurlencode($product ? RoleWcAdcellFeed::product_ref($product) : (string) $item->get_product_id()); $orderQuantities[] = $item->get_quantity(); $orderCount += $item->get_quantity(); } RoleWcAdcell::footer_script(roleWcAdcellRetargetingUrl('checkout', '&basketId=' . rawurlencode($wcOrder->get_order_number()) . '&basketTotal=' . number_format(RoleWcAdcellOrderAmounts::goods_total($wcOrder), 2, '.', '') . '&basketProductCount=' . $orderCount . '&productIds=' . implode(';', $orderProducts) . '&productSeparator=;&quantities=' . implode(';', $orderQuantities) . '&faktor=2')); }