Skip to content

Instantly share code, notes, and snippets.

@juniorthiesen
Last active September 8, 2020 16:46
Show Gist options
  • Save juniorthiesen/c1d2c4029523a23eb5e98b0305ae4469 to your computer and use it in GitHub Desktop.
Save juniorthiesen/c1d2c4029523a23eb5e98b0305ae4469 to your computer and use it in GitHub Desktop.
utm origem
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