Skip to content

Instantly share code, notes, and snippets.

View alewolf's full-sized avatar

Aleksandar alewolf

View GitHub Profile
@alewolf
alewolf / wooptpm-add-custom-dimensions-event-for-ga.php
Created August 3, 2021 09:32
create an event for Google Analytics custom dimensions in woopt WooCommerce Pixel Manager
<?
add_action('wp_head', function () {
?>
<script>
jQuery(document).on('wooptpmAddToCart', function (event, product) {
gtag('event', 'add_to_cart', {
"send_to" : wooptpmDataLayer.pixels.google.analytics.universal.property_id, // this is important to scope it to only GA UA and not send it to other properties
'ecomm_prodid': product.dyn_r_ids[wooptpmDataLayer.pixels.google.analytics.id_type], // you must make sure that the same ID type is being used for GA and Google Ads
'ecomm_pagetype': wooptpmDataLayer.shop.page_type,
@alewolf
alewolf / wooptpm-add-custom-dimensions-to-ga-ua.php
Last active August 3, 2021 09:17
add custom dimensions to Google Universal Analytics in woopt WooCommerce Pixel Manager
<?
add_filter('wooptpm_ga_ua_parameters', function ($analytics_parameters, $analytics_id){
$analytics_parameters['custom_map'] = [
'dimension1' => 'ecomm_prodid',
'dimension2' => 'ecomm_pagetype',
'dimension3' => 'ecomm_totalvalue',
];
return $analytics_parameters;
@alewolf
alewolf / wooptpm_order_items_1.php
Created July 21, 2021 12:44
remve an order item if it's value has been discounted to 0
<?php
// The product ID must be changed and must match the specific product that you want to be removed
add_filter('wooptpm_order_items', function ($order_items, $order){
foreach($order_items as $item_id => $item ){
$product = $item->get_product();
if($product->get_id() === 14 && $item->get_total() == 0) unset($order_items[$item_id]);
/**
* HubSpot custom code action
*
* Capitalizes the first letter of every part of a contact's first name, last name, address and city.
*
* Can easily be configured to update any other contact property.
*
* Examples:
* - john -> John
* - DOE -> Doe
<?php
// https://stackoverflow.com/a/2031935/4688612
// https://stackoverflow.com/q/67277544/4688612
protected function get_visitor_ip(): string
{
$proxy_headers = [
'HTTP_CF_CONNECTING_IP', // Cloudflare
'HTTP_TRUE_CLIENT_IP', // Cloudflare Enterprise
'HTTP_INCAP_CLIENT_IP', // Incapsula
<?php
/*
* Keywords: freemius, readme.txt, changelog, free version, pro version
*
* Description: This code takes a readme.txt of a WordPress plugin, that has been prepared for deployment
* over freemius, and generates a changelog text output with the changelog for the free and one for the pro version.
*/
$source_file = '../src/readme.txt';
@alewolf
alewolf / gist:b37fbd2679afae7abac390090c76c63c
Last active August 25, 2020 11:14
Generic Keywords Remover
/**
* Title: Generic Keywords Remover
* Descritpion: Remove generic keywords from branded search campaigns
* Author: Wolf+Bär Agency, Aleksandar Vucenovic
* Website: https://wolfundbaer.ch
* License: GNU GPLv3
* Version: 0.2
* URL: https://gist.github.com/alewolf/b37fbd2679afae7abac390090c76c63c
* URL:
*/
@alewolf
alewolf / gist:5d933417e35a3d7585b96e2ada9f2e05
Last active July 15, 2020 05:48
resync variable product in WooCommerce
<?php
/***********************************************************************************************
* This function will automatically resync variable product prices in case the prices don't show
* on the catalogue pages anymore.
*
* Simply place it in functions.php
***********************************************************************************************/
add_filter( 'woocommerce_get_price_html', 'resync_variable_product', 100, 2 );
@alewolf
alewolf / gist:e6fcecfba548c765a4ad52d46abcd81e
Last active May 5, 2020 20:41
AdWords Script: Switch all broad match keywords to modified broad match
// Title: Modified Broad Match
// Descritpion: Switch all broad match keywords to modified broad match
// Author: Wolf+Bär Agency, Aleksandar Vucenovic
// License: GNU GPLv3
// Version: 0.3
// URL: https://gist.github.com/alewolf/e6fcecfba548c765a4ad52d46abcd81e
// URL:
// START Settings
@alewolf
alewolf / gist:275278f1da379b56512d
Last active May 5, 2020 09:10
MaxMind GeoIP city locator for unbounce forms
<script type="text/javascript">
$( window ).load(function(){
$.getScript("//geoip-js.com/js/apis/geoip2/v2.1/geoip2.js", function() {
var onSuccess = function(geoipResponse) {
// change '#lp-pom-form-64 #city' to match your form ID and field name
$('#lp-pom-form-64 #city')[0].value = geoipResponse.city.names.en;
};