You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.8 KiB
57 lines
1.8 KiB
|
|
<?
|
|
|
|
use Timber;
|
|
use Timber\PostCollection;
|
|
use Timber\Integrations\WooCommerce\Product as TimberProduct;
|
|
|
|
|
|
Timber::$dirname = [
|
|
'views',
|
|
'modules'
|
|
];
|
|
|
|
// Настройка путей для WooCommerce шаблонов
|
|
add_filter('timber/loader/paths', function($paths) {
|
|
$paths[] = get_template_directory() . '/views/woocommerce';
|
|
return $paths;
|
|
});
|
|
|
|
add_filter( 'timber/integrations', function ( array $integrations ): array {
|
|
$integrations[] = new \Timber\Integrations\WooCommerce\WooCommerceIntegration();
|
|
return $integrations;
|
|
} );
|
|
|
|
|
|
// Add the function to the Timber context
|
|
add_filter('timber/context', function($context) {
|
|
$context['template_path'] = get_template_directory_uri();
|
|
$current_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
|
$context['current_url'] = htmlspecialchars($current_url);
|
|
|
|
// Добавляем WooCommerce контекст если WooCommerce активен
|
|
if (class_exists('WooCommerce')) {
|
|
// WooCommerce автоматически добавляет свой контекст через интеграцию
|
|
// Но мы можем его расширить
|
|
if (is_woocommerce()) {
|
|
$context['is_woocommerce'] = true;
|
|
}
|
|
}
|
|
|
|
return $context;
|
|
});
|
|
|
|
|
|
add_action('init', function() {
|
|
add_filter('timber/context', function($context) {
|
|
$context['current_lang'] = pll_current_language();
|
|
|
|
// Добавляем функцию для получения иконки термина
|
|
$context['get_term_icon'] = function($term_id, $taxonomy) {
|
|
$product = new CosmopetProduct();
|
|
return $product->getTermIcon($term_id, $taxonomy);
|
|
};
|
|
|
|
return $context;
|
|
});
|
|
}, 1);
|
|
|