Untitled
unknown
php
3 years ago
1.1 kB
15
Indexable
/*Добавление yclid в amocrm*/
function catch_yclient_id() {
?>
<script>
function setCookie(name, value, days){
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + value + expires + ";path=/";
}
function getParam(p){
var match = RegExp('[?&]' + p + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
var yclid = getParam('yclid');
if(yclid){
setCookie('yclid', yclid, 90);
}
</script>
<?php
}
add_action('wp_print_scripts', 'catch_yclient_id');
function add_yclid_to_amo($fields, $order)
{
$yclid_field_id = '904771';
if (!empty($_COOKIE['yclid'])) {
$fields[ $yclid_field_id] = $_COOKIE['yclid'];
} else {
$fields[ $yclid_field_id] = '';
}
return $fields;
}
add_filter('itglx_wcamo_lead_fields', 'add_yclid_to_amo', 10, 2);Editor is loading...