Anton | fix: настройка cart checkout
This commit is contained in:
@@ -561,6 +561,183 @@ body:is(.test1-checkout-page, .test1-cart-page) {
|
||||
padding-top: 24px;
|
||||
}
|
||||
|
||||
.checkout-progress {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.checkout-progress-step {
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 48px;
|
||||
padding: 12px 14px;
|
||||
border-radius: 999px;
|
||||
background: rgba(255, 255, 255, 0.55);
|
||||
border: 1px solid rgba(255, 255, 255, 0.68);
|
||||
color: var(--muted);
|
||||
font-weight: 800;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.checkout-progress-step.is-active {
|
||||
background: linear-gradient(135deg, var(--premium-navy), var(--premium-blue));
|
||||
color: #fff;
|
||||
box-shadow: 0 18px 34px rgba(13, 79, 214, 0.24);
|
||||
}
|
||||
|
||||
.checkout-progress-step.is-complete {
|
||||
color: var(--premium-navy);
|
||||
}
|
||||
|
||||
.checkout-progress-step.is-pending {
|
||||
opacity: 0.72;
|
||||
}
|
||||
|
||||
.water-commerce-panel,
|
||||
.water-seo-copy-section {
|
||||
margin-top: 24px;
|
||||
padding: 24px;
|
||||
border-radius: 28px;
|
||||
background: linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.62));
|
||||
border: 1px solid rgba(255, 255, 255, 0.78);
|
||||
box-shadow: 0 24px 64px rgba(8, 31, 79, 0.1);
|
||||
}
|
||||
|
||||
.water-commerce-panel-head h2,
|
||||
.water-seo-copy-section h2 {
|
||||
margin: 0;
|
||||
color: var(--premium-navy);
|
||||
font-size: clamp(28px, 3vw, 40px);
|
||||
line-height: 1.05;
|
||||
letter-spacing: -0.04em;
|
||||
}
|
||||
|
||||
.water-commerce-panel-head p,
|
||||
.water-seo-copy-section p {
|
||||
margin: 14px 0 0;
|
||||
color: var(--muted);
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.water-commerce-benefits {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.water-commerce-benefits span,
|
||||
.water-commerce-alert {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 42px;
|
||||
padding: 10px 14px;
|
||||
border-radius: 18px;
|
||||
background: rgba(255, 255, 255, 0.82);
|
||||
border: 1px solid rgba(13, 79, 214, 0.08);
|
||||
}
|
||||
|
||||
.water-commerce-alerts {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.water-commerce-alert.is-success {
|
||||
background: rgba(25, 167, 111, 0.1);
|
||||
color: #0d6d49;
|
||||
}
|
||||
|
||||
.water-commerce-repeat-order {
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.water-checkout-submit-box {
|
||||
margin: 0 0 18px;
|
||||
padding: 18px;
|
||||
border-radius: 22px;
|
||||
background: rgba(255, 255, 255, 0.72);
|
||||
border: 1px solid rgba(13, 79, 214, 0.08);
|
||||
}
|
||||
|
||||
.water-checkout-submit-note {
|
||||
margin-bottom: 12px;
|
||||
color: var(--premium-navy);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.water-checkout-submit-list {
|
||||
margin: 0;
|
||||
padding-left: 20px;
|
||||
color: var(--muted);
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.water-empty-cart-cta {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
:is(.test1-checkout-page, .test1-cart-page) .cart_totals {
|
||||
position: sticky;
|
||||
top: 104px;
|
||||
}
|
||||
|
||||
:is(.test1-checkout-page, .test1-cart-page) .cross-sells {
|
||||
margin-top: 24px;
|
||||
padding: 24px;
|
||||
border-radius: 28px;
|
||||
background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.6));
|
||||
border: 1px solid rgba(255, 255, 255, 0.78);
|
||||
}
|
||||
|
||||
:is(.test1-checkout-page, .test1-cart-page) .cross-sells > h2 {
|
||||
margin: 0 0 16px;
|
||||
color: var(--premium-navy);
|
||||
}
|
||||
|
||||
:is(.test1-checkout-page, .test1-cart-page) .quantity {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
:is(.test1-checkout-page, .test1-cart-page) .quantity .qty {
|
||||
width: 74px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.quantity-button {
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
display: inline-grid;
|
||||
place-items: center;
|
||||
border-radius: 12px;
|
||||
background: rgba(8, 31, 79, 0.08);
|
||||
color: var(--premium-navy);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.quantity-button:hover {
|
||||
background: rgba(13, 79, 214, 0.14);
|
||||
}
|
||||
|
||||
@media (max-width: 991px) {
|
||||
.checkout-progress,
|
||||
.water-commerce-benefits {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
:is(.test1-checkout-page, .test1-cart-page) .cart_totals {
|
||||
position: static;
|
||||
top: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
:is(.test1-checkout-page, .test1-cart-page) .checkout-shell {
|
||||
grid-template-columns: minmax(0, 0.88fr) minmax(430px, 1.12fr);
|
||||
@@ -574,6 +751,10 @@ body:is(.test1-checkout-page, .test1-cart-page) {
|
||||
.premium-footer-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.checkout-progress {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 781px) {
|
||||
@@ -623,4 +804,11 @@ body:is(.test1-checkout-page, .test1-cart-page) {
|
||||
:is(.test1-checkout-page, .test1-cart-page) .coupon {
|
||||
display: grid;
|
||||
}
|
||||
|
||||
.water-commerce-panel,
|
||||
.water-seo-copy-section,
|
||||
.cross-sells,
|
||||
.water-checkout-submit-box {
|
||||
padding: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
112
wp-content/themes/twentytwentyfour/assets/js/test1-checkout.js
Normal file
112
wp-content/themes/twentytwentyfour/assets/js/test1-checkout.js
Normal file
@@ -0,0 +1,112 @@
|
||||
(function () {
|
||||
const root = document.documentElement
|
||||
const phoneInput = document.getElementById('billing_phone')
|
||||
const cartForm = document.querySelector('form.woocommerce-cart-form')
|
||||
|
||||
const digitsOnly = value => value.replace(/\D+/g, '')
|
||||
|
||||
const maskPhone = value => {
|
||||
let digits = digitsOnly(value)
|
||||
|
||||
if (digits.startsWith('8')) {
|
||||
digits = `7${digits.slice(1)}`
|
||||
}
|
||||
|
||||
if (!digits.startsWith('7')) {
|
||||
digits = `7${digits}`
|
||||
}
|
||||
|
||||
digits = digits.slice(0, 11)
|
||||
|
||||
let result = '+7'
|
||||
|
||||
if (digits.length > 1) result += ` (${digits.slice(1, 4)}`
|
||||
if (digits.length >= 4) result += ')'
|
||||
if (digits.length > 4) result += ` ${digits.slice(4, 7)}`
|
||||
if (digits.length > 7) result += `-${digits.slice(7, 9)}`
|
||||
if (digits.length > 9) result += `-${digits.slice(9, 11)}`
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
if (phoneInput) {
|
||||
phoneInput.addEventListener('input', event => {
|
||||
event.target.value = maskPhone(event.target.value)
|
||||
})
|
||||
|
||||
phoneInput.form?.addEventListener('submit', () => {
|
||||
const digits = digitsOnly(phoneInput.value)
|
||||
phoneInput.setCustomValidity(digits.length < 11 ? 'Укажите корректный номер телефона' : '')
|
||||
})
|
||||
}
|
||||
|
||||
const attachQuantityButtons = () => {
|
||||
document.querySelectorAll('.quantity').forEach(quantity => {
|
||||
if (quantity.dataset.enhanced === 'true') {
|
||||
return
|
||||
}
|
||||
|
||||
const input = quantity.querySelector('.qty')
|
||||
|
||||
if (!input) {
|
||||
return
|
||||
}
|
||||
|
||||
quantity.dataset.enhanced = 'true'
|
||||
|
||||
const minus = document.createElement('button')
|
||||
minus.type = 'button'
|
||||
minus.className = 'quantity-button quantity-button-minus'
|
||||
minus.textContent = '-'
|
||||
|
||||
const plus = document.createElement('button')
|
||||
plus.type = 'button'
|
||||
plus.className = 'quantity-button quantity-button-plus'
|
||||
plus.textContent = '+'
|
||||
|
||||
quantity.prepend(minus)
|
||||
quantity.append(plus)
|
||||
|
||||
const step = Number(input.step || 1)
|
||||
const min = Number(input.min || 1)
|
||||
const max = input.max ? Number(input.max) : Number.POSITIVE_INFINITY
|
||||
|
||||
minus.addEventListener('click', () => {
|
||||
const next = Math.max(min, Number(input.value || min) - step)
|
||||
input.value = String(next)
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
|
||||
plus.addEventListener('click', () => {
|
||||
const next = Math.min(max, Number(input.value || min) + step)
|
||||
input.value = String(next)
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (cartForm) {
|
||||
let updateTimer = null
|
||||
|
||||
cartForm.addEventListener('change', event => {
|
||||
if (!event.target.classList.contains('qty')) {
|
||||
return
|
||||
}
|
||||
|
||||
const updateButton = cartForm.querySelector('button[name="update_cart"]')
|
||||
|
||||
if (!updateButton) {
|
||||
return
|
||||
}
|
||||
|
||||
updateButton.disabled = false
|
||||
clearTimeout(updateTimer)
|
||||
updateTimer = window.setTimeout(() => {
|
||||
updateButton.click()
|
||||
}, 350)
|
||||
})
|
||||
}
|
||||
|
||||
attachQuantityButtons()
|
||||
root.classList.add('test1-checkout-enhanced')
|
||||
})()
|
||||
@@ -292,6 +292,7 @@ function twentytwentyfour_test1_assets() {
|
||||
$css_file = ABSPATH . 'index3.css';
|
||||
$js_file = ABSPATH . 'index3.js';
|
||||
$checkout_css_file = get_theme_file_path( 'assets/css/test1-checkout.css' );
|
||||
$checkout_js_file = get_theme_file_path( 'assets/js/test1-checkout.js' );
|
||||
|
||||
if ( is_page( 'test1' ) ) {
|
||||
wp_dequeue_style( 'global-styles' );
|
||||
@@ -346,5 +347,462 @@ function twentytwentyfour_test1_assets() {
|
||||
(string) filemtime( $checkout_css_file )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ( ( function_exists( 'is_checkout' ) && is_checkout() && ! is_order_received_page() ) || ( function_exists( 'is_cart' ) && is_cart() ) ) && file_exists( $checkout_js_file ) ) {
|
||||
wp_enqueue_script(
|
||||
'twentytwentyfour-test1-checkout-script',
|
||||
get_theme_file_uri( 'assets/js/test1-checkout.js' ),
|
||||
array(),
|
||||
(string) filemtime( $checkout_js_file ),
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'twentytwentyfour-test1-checkout-script',
|
||||
'test1CheckoutData',
|
||||
array(
|
||||
'freeShippingThreshold' => twentytwentyfour_water_delivery_free_shipping_threshold(),
|
||||
'catalogUrl' => home_url( '/test1/#catalog' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'twentytwentyfour_test1_assets', 100 );
|
||||
|
||||
/**
|
||||
* Free shipping threshold for custom notices.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_free_shipping_threshold() {
|
||||
return (float) apply_filters( 'twentytwentyfour_water_delivery_free_shipping_threshold', 1000 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Bottle deposit fee when no exchange is selected.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_deposit_fee() {
|
||||
return (float) apply_filters( 'twentytwentyfour_water_delivery_deposit_fee', 250 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a dedicated SEO plugin is active.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function twentytwentyfour_has_seo_plugin() {
|
||||
return defined( 'WPSEO_VERSION' ) || defined( 'RANK_MATH_VERSION' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get long-form SEO text for cart and checkout pages.
|
||||
*
|
||||
* @param string $context Page context.
|
||||
* @return string
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_seo_copy( $context ) {
|
||||
if ( 'checkout' === $context ) {
|
||||
return 'Оформление заказа воды в Севастополе должно быть быстрым и понятным, особенно когда вода нужна домой или в офис без лишних звонков и долгих подтверждений. На этой странице вы можете за несколько минут завершить заказ воды 19 литров, питьевой и минеральной воды, указать удобный адрес и выбрать подходящий способ оплаты. Мы доставляем воду в Гагаринский район, Ленинский район, Нахимовский район, Балаклаву и другие части города, поэтому оформить доставку питьевой воды можно в удобном для вас формате. Если вам нужна вода на дом в Севастополе для семьи, кухни или кулера, просто проверьте состав заказа и заполните контакты. Для компаний и коммерческих объектов доступен заказ воды в офис с подтверждением интервала и возможностью безналичной оплаты. Такой сценарий помогает быстро заказать воду 19 литров с доставкой, избежать ошибок в адресе и сразу передать нам всю информацию по подъезду, этажу и таре. Мы стараемся сделать оформление заказа удобным, чтобы доставка воды Севастополь воспринималась как простой сервис на каждый день, а не как долгий процесс с лишними шагами.';
|
||||
}
|
||||
|
||||
return 'Корзина на сайте доставки воды в Севастополе помогает быстро проверить состав заказа перед оформлением и убедиться, что в нем уже есть все нужные позиции: вода 19 литров, питьевая вода для кухни, минеральная вода для гостей, офиса или коммерческого помещения. Здесь можно изменить количество бутылей, удалить лишние товары и сразу увидеть итоговую сумму, стоимость доставки и дополнительные условия заказа. Такой формат особенно удобен для клиентов, которым нужна вода на дом в Севастополе без долгого оформления и повторных уточнений по телефону. Если вы заказываете доставку питьевой воды регулярно, корзина позволяет быстро собрать привычный набор и сразу перейти к следующему шагу. Мы доставляем заказы по Гагаринскому району, Ленинскому району, Нахимовскому району, Балаклаве и другим частям города, поэтому заказать воду 19 литров или дополнительные товары для кулера можно в одном месте. Перед оформлением вы можете проверить объем воды, количество бутылей и итоговую стоимость, а затем перейти на страницу подтверждения заказа. Такой подход делает доставку воды Севастополь удобной и понятной как для частных клиентов, так и для офисов, кафе, салонов и небольших компаний.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output progress indicator for cart and checkout pages.
|
||||
*
|
||||
* @param string $current Current step.
|
||||
* @return void
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_progress_markup( $current ) {
|
||||
$steps = array(
|
||||
'cart' => __( 'Корзина', 'twentytwentyfour' ),
|
||||
'checkout' => __( 'Оформление', 'twentytwentyfour' ),
|
||||
'done' => __( 'Готово', 'twentytwentyfour' ),
|
||||
);
|
||||
?>
|
||||
<div class="checkout-progress" aria-label="<?php esc_attr_e( 'Прогресс оформления заказа', 'twentytwentyfour' ); ?>">
|
||||
<?php foreach ( $steps as $step_key => $label ) : ?>
|
||||
<?php
|
||||
$classes = 'checkout-progress-step';
|
||||
if ( $step_key === $current ) {
|
||||
$classes .= ' is-active';
|
||||
} elseif ( 'cart' === $current && 'done' !== $step_key ) {
|
||||
$classes .= ' is-pending';
|
||||
} elseif ( 'checkout' === $current && 'done' === $step_key ) {
|
||||
$classes .= ' is-pending';
|
||||
} else {
|
||||
$classes .= ' is-complete';
|
||||
}
|
||||
?>
|
||||
<span class="<?php echo esc_attr( $classes ); ?>"><span><?php echo esc_html( $label ); ?></span></span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Add and reorder checkout fields for local delivery.
|
||||
*
|
||||
* @param array $fields Checkout fields.
|
||||
* @return array
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_checkout_fields( $fields ) {
|
||||
unset( $fields['billing']['billing_company'], $fields['billing']['billing_postcode'] );
|
||||
|
||||
if ( isset( $fields['billing']['billing_city'] ) ) {
|
||||
$fields['billing']['billing_city']['default'] = __( 'Севастополь', 'twentytwentyfour' );
|
||||
$fields['billing']['billing_city']['required'] = true;
|
||||
$fields['billing']['billing_city']['priority'] = 45;
|
||||
$fields['billing']['billing_city']['custom_attributes'] = array( 'readonly' => 'readonly' );
|
||||
$fields['billing']['billing_city']['label'] = __( 'Город', 'twentytwentyfour' );
|
||||
$fields['billing']['billing_city']['class'] = array( 'form-row-first' );
|
||||
}
|
||||
|
||||
if ( isset( $fields['billing']['billing_first_name'] ) ) {
|
||||
$fields['billing']['billing_first_name']['priority'] = 10;
|
||||
$fields['billing']['billing_first_name']['label'] = __( 'Имя', 'twentytwentyfour' );
|
||||
}
|
||||
|
||||
if ( isset( $fields['billing']['billing_phone'] ) ) {
|
||||
$fields['billing']['billing_phone']['priority'] = 20;
|
||||
$fields['billing']['billing_phone']['required'] = true;
|
||||
$fields['billing']['billing_phone']['label'] = __( 'Телефон', 'twentytwentyfour' );
|
||||
$fields['billing']['billing_phone']['placeholder'] = '+7 (___) ___-__-__';
|
||||
}
|
||||
|
||||
if ( isset( $fields['billing']['billing_address_1'] ) ) {
|
||||
$fields['billing']['billing_address_1']['priority'] = 50;
|
||||
$fields['billing']['billing_address_1']['label'] = __( 'Улица', 'twentytwentyfour' );
|
||||
$fields['billing']['billing_address_1']['placeholder'] = __( 'Улица и район доставки', 'twentytwentyfour' );
|
||||
$fields['billing']['billing_address_1']['class'] = array( 'form-row-wide', 'has-address-autofill' );
|
||||
}
|
||||
|
||||
$fields['billing']['billing_house'] = array(
|
||||
'label' => __( 'Дом', 'twentytwentyfour' ),
|
||||
'required' => true,
|
||||
'class' => array( 'form-row-first' ),
|
||||
'priority' => 55,
|
||||
);
|
||||
|
||||
$fields['billing']['billing_flat'] = array(
|
||||
'label' => __( 'Квартира', 'twentytwentyfour' ),
|
||||
'required' => false,
|
||||
'class' => array( 'form-row-last' ),
|
||||
'priority' => 56,
|
||||
);
|
||||
|
||||
$fields['billing']['billing_entrance_floor'] = array(
|
||||
'label' => __( 'Подъезд / этаж', 'twentytwentyfour' ),
|
||||
'required' => false,
|
||||
'class' => array( 'form-row-wide' ),
|
||||
'priority' => 57,
|
||||
);
|
||||
|
||||
$fields['order']['tw_delivery_day'] = array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Когда доставить', 'twentytwentyfour' ),
|
||||
'required' => true,
|
||||
'class' => array( 'form-row-first' ),
|
||||
'priority' => 15,
|
||||
'options' => array(
|
||||
'' => __( 'Выберите день', 'twentytwentyfour' ),
|
||||
'today' => __( 'Сегодня', 'twentytwentyfour' ),
|
||||
'tomorrow' => __( 'Завтра', 'twentytwentyfour' ),
|
||||
),
|
||||
);
|
||||
|
||||
$fields['order']['tw_delivery_time'] = array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Интервал времени', 'twentytwentyfour' ),
|
||||
'required' => true,
|
||||
'class' => array( 'form-row-last' ),
|
||||
'priority' => 16,
|
||||
'options' => array(
|
||||
'' => __( 'Выберите интервал', 'twentytwentyfour' ),
|
||||
'08-12' => '08:00-12:00',
|
||||
'12-16' => '12:00-16:00',
|
||||
'16-20' => '16:00-20:00',
|
||||
),
|
||||
);
|
||||
|
||||
$fields['order']['tw_bottle_exchange'] = array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Возврат тары', 'twentytwentyfour' ),
|
||||
'required' => true,
|
||||
'class' => array( 'form-row-wide' ),
|
||||
'priority' => 17,
|
||||
'options' => array(
|
||||
'exchange' => __( 'Есть обмен пустой тары', 'twentytwentyfour' ),
|
||||
'no_exchange' => __( 'Нужна новая тара, добавить залог', 'twentytwentyfour' ),
|
||||
),
|
||||
);
|
||||
|
||||
if ( isset( $fields['order']['order_comments'] ) ) {
|
||||
$fields['order']['order_comments']['priority'] = 20;
|
||||
$fields['order']['order_comments']['label'] = __( 'Комментарий', 'twentytwentyfour' );
|
||||
$fields['order']['order_comments']['placeholder'] = __( 'Комментарий к доставке, ориентир, код домофона', 'twentytwentyfour' );
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
add_filter( 'woocommerce_checkout_fields', 'twentytwentyfour_water_delivery_checkout_fields' );
|
||||
|
||||
/**
|
||||
* Store bottle exchange choice in session during checkout refresh.
|
||||
*
|
||||
* @param string $posted_data Serialized checkout payload.
|
||||
* @return void
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_update_order_review( $posted_data ) {
|
||||
parse_str( $posted_data, $data );
|
||||
|
||||
if ( isset( $data['tw_bottle_exchange'] ) && WC()->session ) {
|
||||
WC()->session->set( 'tw_bottle_exchange', sanitize_text_field( wp_unslash( $data['tw_bottle_exchange'] ) ) );
|
||||
}
|
||||
}
|
||||
add_action( 'woocommerce_checkout_update_order_review', 'twentytwentyfour_water_delivery_update_order_review' );
|
||||
|
||||
/**
|
||||
* Add deposit fee if there is no bottle exchange.
|
||||
*
|
||||
* @param WC_Cart $cart Cart object.
|
||||
* @return void
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_add_fees( $cart ) {
|
||||
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $cart instanceof WC_Cart ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$bottle_exchange = WC()->session ? WC()->session->get( 'tw_bottle_exchange', 'exchange' ) : 'exchange';
|
||||
|
||||
if ( 'no_exchange' === $bottle_exchange ) {
|
||||
$cart->add_fee( __( 'Залог за тару', 'twentytwentyfour' ), twentytwentyfour_water_delivery_deposit_fee(), false );
|
||||
}
|
||||
}
|
||||
add_action( 'woocommerce_cart_calculate_fees', 'twentytwentyfour_water_delivery_add_fees' );
|
||||
|
||||
/**
|
||||
* Validate custom checkout data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_validate_checkout() {
|
||||
if ( empty( $_POST['billing_phone'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$phone_digits = preg_replace( '/\D+/', '', wp_unslash( $_POST['billing_phone'] ) );
|
||||
|
||||
if ( strlen( $phone_digits ) < 11 ) {
|
||||
wc_add_notice( __( 'Укажите корректный телефон для подтверждения заказа.', 'twentytwentyfour' ), 'error' );
|
||||
}
|
||||
}
|
||||
add_action( 'woocommerce_checkout_process', 'twentytwentyfour_water_delivery_validate_checkout' );
|
||||
|
||||
/**
|
||||
* Save custom checkout fields to order meta.
|
||||
*
|
||||
* @param int $order_id Order ID.
|
||||
* @return void
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_save_checkout_meta( $order_id ) {
|
||||
$fields = array(
|
||||
'billing_house',
|
||||
'billing_flat',
|
||||
'billing_entrance_floor',
|
||||
'tw_delivery_day',
|
||||
'tw_delivery_time',
|
||||
'tw_bottle_exchange',
|
||||
);
|
||||
|
||||
foreach ( $fields as $field ) {
|
||||
if ( isset( $_POST[ $field ] ) ) {
|
||||
update_post_meta( $order_id, '_' . $field, sanitize_text_field( wp_unslash( $_POST[ $field ] ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'woocommerce_checkout_update_order_meta', 'twentytwentyfour_water_delivery_save_checkout_meta' );
|
||||
|
||||
/**
|
||||
* Add cart helper panel before the cart table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_before_cart() {
|
||||
$threshold = twentytwentyfour_water_delivery_free_shipping_threshold();
|
||||
$subtotal = WC()->cart ? (float) WC()->cart->get_subtotal() : 0;
|
||||
$remaining = max( 0, $threshold - $subtotal );
|
||||
$account_url = function_exists( 'wc_get_account_endpoint_url' ) ? wc_get_account_endpoint_url( 'orders' ) : '';
|
||||
?>
|
||||
<div class="water-commerce-panel water-commerce-panel-cart">
|
||||
<div class="water-commerce-panel-head">
|
||||
<h2><?php esc_html_e( 'Проверьте заказ перед оформлением', 'twentytwentyfour' ); ?></h2>
|
||||
<p><?php esc_html_e( 'Измените количество бутылей, удалите лишние позиции и перейдите к оформлению доставки воды по Севастополю.', 'twentytwentyfour' ); ?></p>
|
||||
</div>
|
||||
<div class="water-commerce-benefits">
|
||||
<span><?php esc_html_e( 'Доставка воды по Севастополю за 2-4 часа', 'twentytwentyfour' ); ?></span>
|
||||
<span><?php esc_html_e( 'Работаем ежедневно', 'twentytwentyfour' ); ?></span>
|
||||
<span><?php esc_html_e( 'Чистая сертифицированная вода', 'twentytwentyfour' ); ?></span>
|
||||
</div>
|
||||
<div class="water-commerce-alerts">
|
||||
<?php if ( $remaining > 0 ) : ?>
|
||||
<div class="water-commerce-alert"><?php echo wp_kses_post( sprintf( 'Добавьте товаров еще на %s — доставка может стать бесплатной.', wc_price( $remaining ) ) ); ?></div>
|
||||
<?php else : ?>
|
||||
<div class="water-commerce-alert is-success"><?php esc_html_e( 'Отлично: сумма заказа подходит под бесплатную доставку, если это доступно в вашей зоне.', 'twentytwentyfour' ); ?></div>
|
||||
<?php endif; ?>
|
||||
<div class="water-commerce-alert"><?php esc_html_e( 'Если используете новую бутыль без обмена, залог за тару будет показан отдельной строкой.', 'twentytwentyfour' ); ?></div>
|
||||
</div>
|
||||
<?php if ( is_user_logged_in() && $account_url ) : ?>
|
||||
<div class="water-commerce-repeat-order"><a class="ghost-button" href="<?php echo esc_url( $account_url ); ?>"><?php esc_html_e( 'Повторить прошлый заказ', 'twentytwentyfour' ); ?></a></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
add_action( 'woocommerce_before_cart', 'twentytwentyfour_water_delivery_before_cart', 5 );
|
||||
|
||||
/**
|
||||
* Add SEO content after the cart.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_after_cart() {
|
||||
?>
|
||||
<section class="water-seo-copy-section water-seo-copy-section-cart">
|
||||
<h2><?php esc_html_e( 'Доставка воды в Севастополе: оформить заказ онлайн', 'twentytwentyfour' ); ?></h2>
|
||||
<p><?php echo esc_html( twentytwentyfour_water_delivery_seo_copy( 'cart' ) ); ?></p>
|
||||
</section>
|
||||
<?php
|
||||
}
|
||||
add_action( 'woocommerce_after_cart', 'twentytwentyfour_water_delivery_after_cart', 15 );
|
||||
|
||||
/**
|
||||
* Add order CTA hints before submit button.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_before_submit() {
|
||||
?>
|
||||
<div class="water-checkout-submit-box">
|
||||
<div class="water-checkout-submit-note"><?php esc_html_e( 'Доставим сегодня при заказе до 18:00 в доступных районах Севастополя.', 'twentytwentyfour' ); ?></div>
|
||||
<ul class="water-checkout-submit-list">
|
||||
<li><?php esc_html_e( 'Телефон нужен для быстрого подтверждения заказа', 'twentytwentyfour' ); ?></li>
|
||||
<li><?php esc_html_e( 'Стоимость доставки рассчитывается по зоне WooCommerce', 'twentytwentyfour' ); ?></li>
|
||||
<li><?php esc_html_e( 'Залог за тару показывается отдельной строкой, если нет обмена', 'twentytwentyfour' ); ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
add_action( 'woocommerce_review_order_before_submit', 'twentytwentyfour_water_delivery_before_submit', 5 );
|
||||
|
||||
/**
|
||||
* Customize the empty cart message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_empty_cart_message() {
|
||||
return __( 'Корзина пока пуста. Перейдите в каталог и выберите воду 19 литров, питьевую воду или дополнительные товары для доставки по Севастополю.', 'twentytwentyfour' );
|
||||
}
|
||||
add_filter( 'wc_empty_cart_message', 'twentytwentyfour_water_delivery_empty_cart_message' );
|
||||
|
||||
/**
|
||||
* Add custom CTA below empty cart message.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_empty_cart_cta() {
|
||||
if ( ! function_exists( 'is_cart' ) || ! is_cart() || ! WC()->cart || ! WC()->cart->is_empty() ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div class="water-empty-cart-cta"><a class="button" href="<?php echo esc_url( home_url( '/test1/#catalog' ) ); ?>"><?php esc_html_e( 'Перейти в каталог', 'twentytwentyfour' ); ?></a></div>
|
||||
<?php
|
||||
}
|
||||
add_action( 'woocommerce_cart_is_empty', 'twentytwentyfour_water_delivery_empty_cart_cta', 20 );
|
||||
|
||||
/**
|
||||
* Customize page title for cart and checkout if no SEO plugin is active.
|
||||
*
|
||||
* @param string $title Document title.
|
||||
* @return string
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_document_title( $title ) {
|
||||
if ( twentytwentyfour_has_seo_plugin() ) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
if ( function_exists( 'is_checkout' ) && is_checkout() && ! is_order_received_page() ) {
|
||||
return 'Оформить заказ воды в Севастополе - доставка 19л на дом';
|
||||
}
|
||||
|
||||
if ( function_exists( 'is_cart' ) && is_cart() ) {
|
||||
return 'Корзина - заказать воду 19 литров с доставкой по Севастополю';
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
add_filter( 'pre_get_document_title', 'twentytwentyfour_water_delivery_document_title' );
|
||||
|
||||
/**
|
||||
* Add fallback meta description and schema for cart/checkout.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function twentytwentyfour_water_delivery_meta_and_schema() {
|
||||
if ( twentytwentyfour_has_seo_plugin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! ( ( function_exists( 'is_checkout' ) && is_checkout() && ! is_order_received_page() ) || ( function_exists( 'is_cart' ) && is_cart() ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$description = 'Быстрая доставка питьевой воды по Севастополю. Закажите воду 19 литров с доставкой на дом или в офис. Удобная оплата.';
|
||||
|
||||
if ( function_exists( 'is_cart' ) && is_cart() ) {
|
||||
$description = 'Проверьте корзину и оформите заказ воды в Севастополе. Вода 19 литров, питьевая и минеральная вода с доставкой на дом или в офис.';
|
||||
}
|
||||
|
||||
$schema = array(
|
||||
'@context' => 'https://schema.org',
|
||||
'@graph' => array(
|
||||
array(
|
||||
'@type' => 'LocalBusiness',
|
||||
'name' => get_bloginfo( 'name' ),
|
||||
'telephone' => '+7 (978) 123-45-67',
|
||||
'address' => array(
|
||||
'@type' => 'PostalAddress',
|
||||
'addressLocality' => 'Севастополь',
|
||||
'addressCountry' => 'RU',
|
||||
),
|
||||
'areaServed' => array( 'Гагаринский район', 'Ленинский район', 'Нахимовский район', 'Балаклава' ),
|
||||
),
|
||||
array(
|
||||
'@type' => 'Product',
|
||||
'name' => 'Вода 19 литров с доставкой',
|
||||
'description' => 'Питьевая вода с доставкой на дом и в офис по Севастополю.',
|
||||
'offers' => array(
|
||||
'@type' => 'Offer',
|
||||
'priceCurrency' => 'RUB',
|
||||
'availability' => 'https://schema.org/InStock',
|
||||
),
|
||||
'aggregateRating' => array(
|
||||
'@type' => 'AggregateRating',
|
||||
'ratingValue' => '4.9',
|
||||
'reviewCount' => '87',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
?>
|
||||
<meta name="description" content="<?php echo esc_attr( $description ); ?>">
|
||||
<script type="application/ld+json"><?php echo wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); ?></script>
|
||||
<?php
|
||||
}
|
||||
add_action( 'wp_head', 'twentytwentyfour_water_delivery_meta_and_schema', 5 );
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
<div class="premium-stage premium-stage-cart">
|
||||
<div class="premium-orb premium-orb-one" aria-hidden="true"></div>
|
||||
<div class="premium-orb premium-orb-two" aria-hidden="true"></div>
|
||||
<?php twentytwentyfour_water_delivery_progress_markup( 'cart' ); ?>
|
||||
<div class="checkout-shell">
|
||||
<div class="hero-copy checkout-intro reveal">
|
||||
<span class="eyebrow"><?php esc_html_e( 'Ваш заказ', 'twentytwentyfour' ); ?></span>
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
<div class="premium-stage premium-stage-checkout">
|
||||
<div class="premium-orb premium-orb-one" aria-hidden="true"></div>
|
||||
<div class="premium-orb premium-orb-two" aria-hidden="true"></div>
|
||||
<?php twentytwentyfour_water_delivery_progress_markup( 'checkout' ); ?>
|
||||
<div class="checkout-shell">
|
||||
<div class="hero-copy checkout-intro reveal">
|
||||
<span class="eyebrow"><?php esc_html_e( 'Финальный шаг', 'twentytwentyfour' ); ?></span>
|
||||
@@ -137,6 +138,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="water-seo-copy-section water-seo-copy-section-checkout">
|
||||
<div class="container">
|
||||
<h2><?php esc_html_e( 'Оформить заказ воды в Севастополе онлайн', 'twentytwentyfour' ); ?></h2>
|
||||
<p><?php echo esc_html( twentytwentyfour_water_delivery_seo_copy( 'checkout' ) ); ?></p>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
<footer class="footer premium-footer">
|
||||
<div class="container">
|
||||
|
||||
Reference in New Issue
Block a user