|
|
|
@ -7,16 +7,40 @@ |
|
|
|
|
// return $params; |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!class_exists('WooCommerce')) { |
|
|
|
|
return; // Прерываем, если WooCommerce не активен |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Откладываем выполнение фильтра timber/context |
|
|
|
|
add_action('wp', function() { |
|
|
|
|
add_filter('timber/context', function($context) { |
|
|
|
|
$context['cart_count'] = 0; |
|
|
|
|
if (class_exists('WooCommerce') && !is_null(WC()->cart)) { |
|
|
|
|
$context['cart_count'] = WC()->cart->get_cart_contents_count(); |
|
|
|
|
} |
|
|
|
|
if (defined('WP_IMPORTING') && WP_IMPORTING) { |
|
|
|
|
$context['cart_count'] = 0; |
|
|
|
|
} |
|
|
|
|
return $context; |
|
|
|
|
}); |
|
|
|
|
}, 20); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Подключение скриптов для AJAX-добавления в корзину |
|
|
|
|
add_action('wp_enqueue_scripts', 'enable_ajax_add_to_cart_single'); |
|
|
|
|
function enable_ajax_add_to_cart_single() { |
|
|
|
|
if (is_product()) { |
|
|
|
|
wp_enqueue_script('wc-add-to-cart-variation'); // для вариативных товаров |
|
|
|
|
wp_enqueue_script('wc-add-to-cart'); // основной скрипт для добавления в корзину |
|
|
|
|
wp_enqueue_script('wc-add-to-cart-variation'); |
|
|
|
|
wp_enqueue_script('wc-add-to-cart'); |
|
|
|
|
error_log('WooCommerce scripts enqueued on product page'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Добавление перевода для WooCommerce скриптов |
|
|
|
|
add_filter('woocommerce_get_script_data', 'add_custom_woocommerce_params', 10, 2); |
|
|
|
|
function add_custom_woocommerce_params($params, $handle) { |
|
|
|
|
if (in_array($handle, ['wc-cart', 'wc-add-to-cart'])) { |
|
|
|
|
$params['i18n_restore_item'] = function_exists('pll__') ? pll__('Восстановить') : __('Восстановить', 'cosmopet'); |
|
|
|
|
} |
|
|
|
|
return $params; |
|
|
|
|
} |