Custom WooCommerce theme for orgsteklo.ru including: - Product catalog with category/subcategory hierarchy - Custom checkout with delivery calculation - Price calculator - Admin settings panel - Search functionality - User account pages
117 lines
6.5 KiB
PHP
117 lines
6.5 KiB
PHP
<?php
|
||
defined( 'ABSPATH' ) || exit;
|
||
$formatted_destination = isset( $formatted_destination ) ? $formatted_destination : WC()->countries->get_formatted_address( $package['destination'], ', ' );
|
||
$has_calculated_shipping = ! empty( $has_calculated_shipping );
|
||
$show_shipping_calculator = ! empty( $show_shipping_calculator );
|
||
$calculator_text = '';
|
||
?>
|
||
<div class="checkout-col">
|
||
<div class="checkout-name">
|
||
<span>2</span>
|
||
<h3>Способ доставки</h3>
|
||
</div>
|
||
<div class="checkout-block">
|
||
<?php if ( ! empty( $available_methods ) && is_array( $available_methods ) ) : ?>
|
||
<ul id="shipping_method" class="woocommerce-shipping-methods checkout-delivery">
|
||
<?php foreach ( $available_methods as $method ) : ?>
|
||
<li>
|
||
<div class="checkout-delivery__item">
|
||
<?php
|
||
$method_id = esc_attr( $method->id );
|
||
$method_title = $method->get_label();
|
||
$method_name = sanitize_title( $method_title );
|
||
$is_checked = checked( $method_id, $chosen_method, false );
|
||
$input_type = ( count( $available_methods ) > 1 ) ? 'radio' : 'hidden';
|
||
$cost = floatval( $method->cost );
|
||
|
||
// Общий префикс <input>
|
||
$input = sprintf(
|
||
'<input type="%1$s" name="shipping_method[%2$d]" data-index="%2$d" id="shipping_method_%2$d_%3$s" value="%4$s" class="shipping_method" data-cost="%6$s" %5$s>',
|
||
$input_type,
|
||
$index,
|
||
$method_name,
|
||
$method_id,
|
||
$is_checked,
|
||
esc_attr( $cost )
|
||
);
|
||
|
||
// Маппинг названий к ключам настроек
|
||
$label_keys = array(
|
||
'Самовывоз' => 'samovyvoz_label',
|
||
'Доставка по Москве' => 'moscow_label',
|
||
'Доставка по Московской области' => 'moscow_area_label',
|
||
'В другой регион' => 'region_label',
|
||
'В другой регион Почтой России' => 'pochta_label',
|
||
);
|
||
|
||
echo $input;
|
||
|
||
if ( isset( $label_keys[ $method_title ] ) ) {
|
||
$desc = orgsteklo_get_checkout_setting( $label_keys[ $method_title ] );
|
||
// Подставляем {cost} → реальную стоимость из WooCommerce
|
||
$desc = str_replace( '{cost}', wc_price( $cost ), $desc );
|
||
// Подставляем {km_rate} → стоимость за км от МКАД
|
||
$km_rate = orgsteklo_get_checkout_setting( 'moscow_area_km_rate' );
|
||
$desc = str_replace( '{km_rate}', esc_html( $km_rate ), $desc );
|
||
printf(
|
||
'<label for="shipping_method_%1$d_%2$s"><p>%3$s</p><p>%4$s</p></label>',
|
||
$index,
|
||
$method_name,
|
||
esc_html( $method_title ),
|
||
wp_kses_post( $desc )
|
||
);
|
||
} else {
|
||
printf(
|
||
'<label for="shipping_method_%1$d_%2$s"><p>%3$s</p></label>',
|
||
$index,
|
||
$method_name,
|
||
esc_html( $method_title )
|
||
);
|
||
}
|
||
|
||
do_action( 'woocommerce_after_shipping_rate', $method, $index );
|
||
?>
|
||
</div>
|
||
</li>
|
||
<?php endforeach; ?>
|
||
</ul>
|
||
<?php if ( is_cart() ) : ?>
|
||
<p class="woocommerce-shipping-destination">
|
||
<?php
|
||
if ( $formatted_destination ) {
|
||
printf( esc_html__( 'Shipping to %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' );
|
||
$calculator_text = esc_html__( 'Change address', 'woocommerce' );
|
||
} else {
|
||
echo wp_kses_post( apply_filters( 'woocommerce_shipping_estimate_html', __( 'Shipping options will be updated during checkout.', 'woocommerce' ) ) );
|
||
}
|
||
?>
|
||
</p>
|
||
<?php endif; ?>
|
||
<?php
|
||
elseif ( ! $has_calculated_shipping || ! $formatted_destination ) :
|
||
if ( is_cart() && 'no' === get_option( 'woocommerce_enable_shipping_calc' ) ) {
|
||
echo wp_kses_post( apply_filters( 'woocommerce_shipping_not_enabled_on_cart_html', __( 'Shipping costs are calculated during checkout.', 'woocommerce' ) ) );
|
||
} else {
|
||
echo wp_kses_post( apply_filters( 'woocommerce_shipping_may_be_available_html', __( 'Enter your address to view shipping options.', 'woocommerce' ) ) );
|
||
}
|
||
elseif ( ! is_cart() ) :
|
||
echo wp_kses_post( apply_filters( 'woocommerce_no_shipping_available_html', __( 'There are no shipping options available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) );
|
||
else :
|
||
echo wp_kses_post(
|
||
apply_filters(
|
||
'woocommerce_cart_no_shipping_available_html',
|
||
sprintf( esc_html__( 'No shipping options were found for %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' ),
|
||
$formatted_destination
|
||
)
|
||
);
|
||
$calculator_text = esc_html__( 'Enter a different address', 'woocommerce' );
|
||
endif;
|
||
?>
|
||
<?php if ( $show_package_details ) : ?>
|
||
<?php echo '<p class="woocommerce-shipping-contents"><small>' . esc_html( $package_details ) . '</small></p>'; ?>
|
||
<?php endif; ?>
|
||
<?php if ( $show_shipping_calculator ) : ?>
|
||
<?php woocommerce_shipping_calculator( $calculator_text ); ?>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|