['mode' => 'production', 'region' => 'ru'],
'cosmopet.ae' => ['mode' => 'production', 'region' => 'ae'],
'cosmopet-test-dumb.cp.good-production.xyz' => ['mode' => 'develope', 'region' => 'ru'],
'cosmopet-test-ru.cp.good-production.xyz' => ['mode' => 'develope', 'region' => 'ru'],
'cosmopet-test-ae.cp.good-production.xyz' => ['mode' => 'develope', 'region' => 'ae'],
];
$host = strtolower($host ?: $_SERVER['SERVER_NAME']);
$config = $map[$host] ?? ['mode' => 'develope', 'region' => 'unknown'];
$this->site_mode = $config['mode'];
$this->site_region = $config['region'];
}
}
add_filter('timber/twig', function (\Twig\Environment $twig) {
global $site_env;
$twig->addGlobal('site_region', $site_env->site_region);
$twig->addGlobal('site_mode', $site_env->site_mode);
$twig->addGlobal('header_scripts', get_field('header_scripts', 'option')); // со страницы "Общих настроек контента ACF"
return $twig;
});
/* End | Работа с проверкой мультисайтовости и стендов */
add_filter('woocommerce_currency_symbol', 'change_aed_currency_symbol', 10, 2);
function change_aed_currency_symbol($currency_symbol, $currency) {
if ($currency == 'AED') {
$currency_symbol = 'AED';
}
return $currency_symbol;
}
// Отключаем канонические ссылки и hreflang от Yoast SEO
add_filter('wpseo_canonical', '__return_false');
add_filter('wpseo_opengraph_url', '__return_false'); // Отключаем OG URL
add_filter('wpseo_add_x_default_hreflang', '__return_false'); // Отключаем hreflang от Yoast
add_filter('wpseo_disable_adjacent_rel_links', '__return_true'); // Отключаем соседние rel-ссылки
// Добавляем каноническую ссылку
add_action('wp_head', 'custom_canonical_url', 5);
function custom_canonical_url() {
if (!is_admin()) {
// Защищаем от дублирования
static $canonical_added = false;
if ($canonical_added) {
return;
}
$canonical_added = true;
// Формируем текущий URL без лишних параметров
$current_url = trailingslashit(home_url($_SERVER['REQUEST_URI']));
// Удаляем возможные параметры запроса, если они не нужны
$current_url = strtok($current_url, '?');
echo '' . "\n";
}
}
/**
* Добавление событий контрибуции для FP Pixel
* только на боевом сайте АЕ
* */
if($site_env->site_mode == 'production' and $site_env->site_region == 'ae') {
/* Передача просто по url */
add_action('wp_footer', 'add_facebook_pixel_events');
function add_facebook_pixel_events() {
// 1. Событие AddToCart (Добавление в корзину)
if (is_product() || is_shop() || is_cart()) {
?>
get_status() !== 'processing' && $order->get_status() !== 'completed')) return;
$items = [];
foreach ($order->get_items() as $item) {
$product = $item->get_product();
$items[] = [
'item_id' => $product->get_id(),
'item_name' => $product->get_name(),
'price' => $product->get_price(),
'quantity' => $item->get_quantity()
];
}
?>
cart ? WC()->cart->get_total('edit') : 0;
?>
get_status() !== 'processing' && $order->get_status() !== 'completed')
return; // Отправляем только для оплаченных заказов
$items = [];
foreach ($order->get_items() as $item) {
$product = $item->get_product();
$items[] = [
'id' => $product->get_id(),
'name' => $product->get_name(),
'price' => $product->get_price(),
'quantity' => $item->get_quantity()
];
}
// Получаем валюту заказа
$currency = $order->get_currency();
?>