Last active
September 8, 2020 16:46
-
-
Save juniorthiesen/c1d2c4029523a23eb5e98b0305ae4469 to your computer and use it in GitHub Desktop.
utm origem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wp_set_origin_cookie() { | |
$cookie_value = $_SERVER['HTTP_REFERER']; | |
if ( ! is_admin() && ! isset( $_COOKIE['origin'] ) ) { | |
setcookie( 'origin', $cookie_value, time() + 3600*24*30, COOKIEPATH, COOKIE_DOMAIN, false ); | |
} | |
} | |
add_action( 'init', 'wp_set_origin_cookie'); | |
function wp_add_order_referrer( $order ) { | |
$order->add_meta_data( 'referrer', $_COOKIE['origin'] ); | |
} | |
add_action('woocommerce_checkout_create_order', 'wp_add_order_referrer', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment