From b7312ebf1b2f4814589d24dd3ab14cbc2bfcd020 Mon Sep 17 00:00:00 2001 From: maksim Date: Mon, 23 Jun 2025 11:13:05 +0300 Subject: [PATCH] =?UTF-8?q?Task=206913=20|=20=D0=98=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=D0=BE=D0=B2=20=D0=B2?= =?UTF-8?q?=20=D0=BA=D0=B0=D1=80=D1=82=D0=BE=D1=87=D0=BA=D0=B5=20=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=80=D0=B0.=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=20=D0=B4=D0=BE=D0=BF=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=B0=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=20=D0=BD=D0=B5=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=D0=B5=20=D1=81=20"=D0=92=D0=B5=D1=81"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/catalog/assets/js/gp-main.js | 2 +- .../custom-admin-panel-logic.php | 35 ++++++++++--------- .../temp-functions/woocommerce-logic.php | 14 +++++--- .../_blocks/shop/archive-product-tease.twig | 4 +-- .../templates/_pages/shop/product-single.twig | 2 +- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/wp-content/themes/cosmopet/modules/shop/components/catalog/assets/js/gp-main.js b/wp-content/themes/cosmopet/modules/shop/components/catalog/assets/js/gp-main.js index 7411ca6..48e293a 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/catalog/assets/js/gp-main.js +++ b/wp-content/themes/cosmopet/modules/shop/components/catalog/assets/js/gp-main.js @@ -53,7 +53,7 @@ jQuery(document).ready(function ($) { window.t = product.find('.product-item-overlay__price-val') console.log(t) var new_price = price * Number(qty) - product.find('.product-item-overlay__price').html(new_price + ' '); + product.find('.product-item-overlay__price-val').html(new_price + ' '); product.find('.select__state').data('product_price', price).data('product_id', id).val($(this).text().trim()); product.find('.state__block').removeClass('expanded').css('height', '0'); diff --git a/wp-content/themes/cosmopet/temp-functions/custom-admin-panel-logic.php b/wp-content/themes/cosmopet/temp-functions/custom-admin-panel-logic.php index f2cd65d..b09a06f 100644 --- a/wp-content/themes/cosmopet/temp-functions/custom-admin-panel-logic.php +++ b/wp-content/themes/cosmopet/temp-functions/custom-admin-panel-logic.php @@ -39,33 +39,33 @@ add_action('woocommerce_product_data_panels', function () { /* Добавил пользовательское поле "Объем" во вкладку "Доставка" */ add_action('woocommerce_product_options_dimensions', function () { global $post; - // $val = get_post_meta($post->ID, '_volume', true); // получить значения сохраненные в БД - // woocommerce_wp_text_input( - // array( - // 'id' => '_volume', - // 'label' => 'Объем (мл)', - // 'placeholder' => 'Отобразится вместо "Вес"', - // 'desc_tip' => true, - // 'description' => 'Будет выводится вместо веса, если заполнить', - // 'value' => $val // вывести значения из БД в поле - // ) - // ); - // НА будуще если понадобится выпадающий список сделать для выбора единицы измерения - $val = get_post_meta($post->ID, '_custom_measurement', true); // получить значения сохраненные в БД + + // Поле: единица измерения (для "Вес") + $val_measurement = get_post_meta($post->ID, '_custom_measurement', true); woocommerce_wp_select( array( 'id' => '_custom_measurement', - 'label' => 'Ед. измерения (для "Вес")', + 'label' => 'Ед. измерения (будет отображаться в карточке товара если Вес товара не равен значению - заполнять значение размера в "Размер для отображения")', 'description' => 'Выбранная единица измерения будет выводится вместо кг', 'desc_tip' => true, 'options' => array( - 'кг' => 'кг (по умолчанию)', // по умолчанию - // 'мм' => 'мм', + 'кг' => 'кг (по умолчанию)', 'мл' => 'мл', 'л' => 'л', ) ) ); + + // Поле: Размер для отображения + $val_size = get_post_meta($post->ID, '_size_for_display', true); + woocommerce_wp_text_input(array( + 'id' => '_size_for_display', + 'label' => 'Размер для отображения', + 'placeholder' => 'Заполните размер для отображения', + 'desc_tip' => true, + 'description' => 'Этот размер будет выводиться на карточке товара', + 'value' => $val_size, + )); }); @@ -80,6 +80,9 @@ add_action('woocommerce_process_product_meta', function ($post_id) { if (isset($_POST['_custom_measurement'])) { update_post_meta($post_id, '_custom_measurement', sanitize_textarea_field($_POST['_custom_measurement'])); } + if (isset($_POST['_size_for_display'])) { + update_post_meta($post_id, '_size_for_display', sanitize_textarea_field($_POST['_size_for_display'])); + } }); /** diff --git a/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php b/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php index 991c102..4537a23 100644 --- a/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php +++ b/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php @@ -98,15 +98,21 @@ function get_product_info ($id, $type) { } $product = wc_get_product($id); - $custom_measurement = get_post_meta($id, '_custom_measurement', true) ?: 'кг'; - + $custom_measurement = get_post_meta($id, '_custom_measurement', true) ?: pll__('кг'); + $custom_size = get_post_meta($id, '_size_for_display', true) ?: ''; if (!$product) { return ''; } if ($type == 'price') { return $product->get_price(); - } elseif ($type == 'weight') { - return $product->get_weight() ? $product->get_weight() . ' ' . $custom_measurement : ''; + } + elseif ($type == 'weight') { + if ($custom_size){ + return $custom_size ? $custom_size . ' ' . $custom_measurement : '';; + } + else{ + return $product->get_weight() ? $product->get_weight() . ' ' . $custom_measurement : ''; + } } return ''; } diff --git a/wp-content/themes/cosmopet/templates/_blocks/shop/archive-product-tease.twig b/wp-content/themes/cosmopet/templates/_blocks/shop/archive-product-tease.twig index 846edc5..7c42427 100644 --- a/wp-content/themes/cosmopet/templates/_blocks/shop/archive-product-tease.twig +++ b/wp-content/themes/cosmopet/templates/_blocks/shop/archive-product-tease.twig @@ -105,9 +105,9 @@ {% set siblings = function('get_collection_siblings' , term.id) %} {% for sibling in siblings %} - + {% set weight = function('get_product_info', sibling.ID, 'weight') %} - + {% set s_product = TimberPost(sibling.ID) %} {% set s_in_stock = s_product.meta('_stock_status') == 'instock' %} {% if s_in_stock %} diff --git a/wp-content/themes/cosmopet/templates/_pages/shop/product-single.twig b/wp-content/themes/cosmopet/templates/_pages/shop/product-single.twig index 3fe9709..70502eb 100644 --- a/wp-content/themes/cosmopet/templates/_pages/shop/product-single.twig +++ b/wp-content/themes/cosmopet/templates/_pages/shop/product-single.twig @@ -138,7 +138,7 @@ data-product_id="{{ sibling.ID }}" data-product_price="{{ product_price }}" > - {{ product_weight|upper }} + {{ weight|upper }} {% endfor %}