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.
70 lines
2.4 KiB
70 lines
2.4 KiB
<?php
|
|
|
|
add_action('wp_ajax_get_cart_fragment', 'get_cart_fragment_callback');
|
|
add_action('wp_ajax_nopriv_get_cart_fragment', 'get_cart_fragment_callback');
|
|
|
|
function get_cart_fragment_callback() {
|
|
// Проверяем nonce для безопасности
|
|
check_ajax_referer('woocommerce-cart', 'security', false);
|
|
|
|
// Получаем содержимое корзины
|
|
ob_start();
|
|
wc_get_template('shop/cart-contents.twig', [], '', get_template_directory() . '/templates/');
|
|
$contents = ob_get_clean();
|
|
|
|
// Получаем футер корзины
|
|
ob_start();
|
|
wc_get_template('modal-basket-footer.twig', [], '', get_template_directory() . '/templates/');
|
|
$footer = ob_get_clean();
|
|
|
|
// Получаем данные корзины
|
|
$cart = WC()->cart;
|
|
$count = $cart->get_cart_contents_count();
|
|
$total = $cart->get_total('raw'); // Числовая сумма
|
|
$total_html = wc_cart_totals_order_total_html(); // Форматированная сумма
|
|
|
|
wp_send_json_success([
|
|
'contents' => $contents,
|
|
'footer' => $footer,
|
|
'count' => $count,
|
|
'total' => $total_html,
|
|
'total_raw' => $total
|
|
]);
|
|
}
|
|
|
|
add_action('template_redirect', 'custom_redirect_cart_page');
|
|
function custom_redirect_cart_page() {
|
|
if (is_cart()) {
|
|
wp_redirect(home_url('/'));
|
|
exit;
|
|
}
|
|
}
|
|
|
|
add_action('wp_enqueue_scripts', 'remove_woocommerce_styles_on_checkout', 9999);
|
|
function remove_woocommerce_styles_on_checkout() {
|
|
// Проверяем, что мы на странице чекаута
|
|
if (function_exists('is_checkout') && is_checkout() && !is_order_received_page()) {
|
|
wp_deregister_style('woocommerce-layout');
|
|
wp_deregister_style('woocommerce-smallscreen');
|
|
wp_deregister_style('woocommerce-general');
|
|
|
|
// Дополнительно: отключить другие стили WooCommerce
|
|
wp_dequeue_style('select2');
|
|
wp_deregister_style('select2');
|
|
}
|
|
}
|
|
|
|
add_action('wp_head', 'custom_checkout_padding');
|
|
function custom_checkout_padding() {
|
|
// Проверяем, что это страница Checkout
|
|
if (is_checkout() && !is_admin()) {
|
|
?>
|
|
<style type="text/css">
|
|
main.wrapper {
|
|
padding-top: 100px;
|
|
padding-bottom: 50px;
|
|
}
|
|
</style>
|
|
<?php
|
|
}
|
|
}
|
|
|