ID, 'product_cat'); $categoryId = $terms[0]->term_id; $categoryName = urlencode($terms[0]->name); $productIdString = implode(';', $productIds); if(is_search()) { $roleWcAdcellTrackingScriptRetargeting = '//www.adcell.de/js/inlineretarget.js?method=search&pid='.esc_attr(get_option('roleWcAdcellProgramId')).'&search='. get_search_query(true) .'&productIds='. $productIdString .'&productSeparator=;'; } else { $roleWcAdcellTrackingScriptRetargeting = '//www.adcell.de/js/inlineretarget.js?method=category&pid='.esc_attr(get_option('roleWcAdcellProgramId')).'&categoryName='.$categoryName.'&categoryId='. $categoryId .'&productIds='. $productIdString . '&productSeparator=;'; } wp_enqueue_script('roleWcAdcellTrackingRetargetingScriptCategory', $roleWcAdcellTrackingScriptRetargeting); } /** * Generates productpagereatrgeting script */ function roleWcAdcellTrackingProductRetargeting() { global $product; $relatedProducts = wc_get_related_products($product->get_id()); $relatedProductsString = implode(';', $relatedProducts); $categoryId = $product->get_category_ids()[0]; wp_enqueue_script('roleWcAdcellTrackingRetargetingScriptProduct', '//www.adcell.de/js/inlineretarget.js?method=product&pid='.esc_attr(get_option('roleWcAdcellProgramId')).'&productId='. $product->get_id() .'&productName='. $product->get_name() .'&categoryId='. $categoryId .'&productIds='. $relatedProductsString .'&productSeparator=;'); } /** * Generates cartretargeting script */ function roleWcAdcellTrackingCartRetargeting() { global $woocommerce; $items = $woocommerce->cart->get_cart(); $cartProducts = array(); $cartQuantities = array(); $cartCount = 0; $cartAmount = 0.0; foreach($items as $item => $values) { $cartProducts[] = $values['data']->get_id(); $cartQuantities[] = $values['quantity']; $cartCount += $values['quantity']; $cartAmount += $values['line_total']; } $cartProductsString = implode(';', $cartProducts); $cartQuantitiesString = implode(';', $cartQuantities); wp_enqueue_script('roleWcAdcellTrackingRetargetingScriptCart', '//www.adcell.de/js/inlineretarget.js?method=basket&pid='.esc_attr(get_option('roleWcAdcellProgramId')).'&productIds='. $cartProductsString .'&productSeparator=;&quantities='. $cartQuantitiesString .'&basketProductCount='. $cartCount .'&basketTotal='. $cartAmount); } /** * Generates orderretargeting script */ function roleWcAdcellTrackingOrderRetargeting($orderID) { $wcOrder = wc_get_order($orderID); $total = $wcOrder->get_total() - $wcOrder->get_shipping_total() - $wcOrder->get_total_tax(); $items = $wcOrder->get_items(); $orderProducts = array(); $orderQuantities = array(); $orderCount = 0; foreach($items as $item => $values) { $orderProducts[] = $values['product_id']; $orderQuantities[] = $values['quantity']; $orderCount += $values['quantity']; } $orderProductsString = implode(';', $orderProducts); $orderQuantitiesString = implode(';', $orderQuantities); wp_enqueue_script('roleWcAdcellTrackingRetargetingScriptOrder', '//www.adcell.de/js/inlineretarget.js?method=checkout&pid='. esc_attr(get_option('roleWcAdcellProgramId')) . '&basketId='. $wcOrder->get_order_number() .'&basketTotal='. $total .'&basketProductCount='. $orderCount .'&productIds='. $orderProductsString .'&productSeparator=;&quantities='. $orderQuantitiesString); }