From beffd44cb91ff36340b8a8ef57aeca097da1dff6 Mon Sep 17 00:00:00 2001 From: maksim Date: Sun, 22 Jun 2025 20:59:16 +0300 Subject: [PATCH] =?UTF-8?q?Task=205453=20|=20=D0=B2=D1=8B=D0=B2=D0=B5?= =?UTF-8?q?=D0=BB=20=D0=B2=20=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA=D0=B5=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=BF=D0=B0=D0=B4=D0=B0=D1=8E=D1=89=D0=B8=D0=B9=20?= =?UTF-8?q?=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20=D1=81=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=BE=D0=BC=20=D0=B5=D0=B4.=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D1=80=D0=B5=D0=BD=D0=B8=D1=8F,=20=D0=BA=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D0=BF=D1=80=D0=B8=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B2=D0=BE=D0=B4=D0=B8=D1=82=D1=81=D1=8F=20=D0=B2=D0=BC?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=BE=20=D0=9A=D0=93=20=D0=BD=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B4=D1=80=D0=BE=D0=B1=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B5=20=D0=B8=20=D0=B2=20=D0=BB?= =?UTF-8?q?=D0=B8=D1=81=D1=82=D0=B8=D0=BD=D0=B3=D0=B5=20=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../single-product/component-controller.php | 5 -- .../modules/shop/module-controller.php | 7 +-- .../custom-admin-panel-logic.php | 49 +++++++++++-------- .../temp-functions/woocommerce-logic.php | 5 +- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php b/wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php index 44fca9a..7c753c9 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php +++ b/wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php @@ -51,11 +51,6 @@ if (function_exists('is_product') && is_product()) { } } - // echo '
';
-    // var_dump($attributes);
-    // print_r($attributes);
-    // echo '
'; - // die(); $context_for_twig['product_attributes'] = $attributes; diff --git a/wp-content/themes/cosmopet/modules/shop/module-controller.php b/wp-content/themes/cosmopet/modules/shop/module-controller.php index c784347..221cc05 100644 --- a/wp-content/themes/cosmopet/modules/shop/module-controller.php +++ b/wp-content/themes/cosmopet/modules/shop/module-controller.php @@ -323,16 +323,13 @@ function auto_fill_shipping_fields_from_billing( $order_id ) { if (function_exists('is_product') && is_product()) { $product_id = get_the_ID(); $product = wc_get_product($product_id); - // echo '
';
-            // print_r($product->get_price());
-            // echo '
'; - // die(); + $custom_measurement = get_post_meta($product_id, '_custom_measurement', true) ?: 'кг'; if ($product) { $context['product'] = $product; $context['product_id'] = $product_id; $context['product_price'] = $product->get_price(); - $context['product_weight'] = $product->get_weight() . ' кг'; + $context['product_weight'] = $product->get_weight() . ' ' . $custom_measurement; $terms = get_the_terms($product_id, 'product_cat'); 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 c0d7ba4..f2cd65d 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 @@ -38,30 +38,34 @@ add_action('woocommerce_product_data_panels', function () { /* Добавил пользовательское поле "Объем" во вкладку "Доставка" */ add_action('woocommerce_product_options_dimensions', function () { - woocommerce_wp_text_input( + 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); // получить значения сохраненные в БД + woocommerce_wp_select( array( - 'id' => '_volume', - 'label' => 'Объем (мл)', + 'id' => '_custom_measurement', + 'label' => 'Ед. измерения (для "Вес")', + 'description' => 'Выбранная единица измерения будет выводится вместо кг', 'desc_tip' => true, - 'description' => 'Выбранная единица измерения будет подставляться вместо КГ', - 'value' => 'test' // вывести значения из БД в поле + 'options' => array( + 'кг' => 'кг (по умолчанию)', // по умолчанию + // 'мм' => 'мм', + 'мл' => 'мл', + 'л' => 'л', + ) ) ); - // НА будуще если понадобится выпадающий список сделать для выбора единицы измерения - // woocommerce_wp_select( - // array( - // 'id' => '_custom_measurement', - // 'label' => 'Единица измерения (для "Вес")', - // 'description' => 'Выбранная единица измерения будет подставляться вместо КГ', - // // 'desc_tip' => true, - // 'options' => array( - // 'мм' => 'Выберите...', - // 'simple' => 'Простой', - // 'variable' => 'Вариативный', - // 'custom' => 'Пользовательский' - // ) - // ) - // ); }); @@ -71,7 +75,10 @@ add_action('woocommerce_process_product_meta', function ($post_id) { update_post_meta($post_id, '_composition', sanitize_textarea_field($_POST['_composition'])); } if (isset($_POST['_volume'])) { - update_post_meta($post_id, '_composition', sanitize_textarea_field($_POST['_composition'])); + update_post_meta($post_id, '_volume', sanitize_textarea_field($_POST['_volume'])); + } + if (isset($_POST['_custom_measurement'])) { + update_post_meta($post_id, '_custom_measurement', sanitize_textarea_field($_POST['_custom_measurement'])); } }); diff --git a/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php b/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php index a2b28a4..991c102 100644 --- a/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php +++ b/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php @@ -96,14 +96,17 @@ function get_product_info ($id, $type) { if (!$id) { return ''; } + $product = wc_get_product($id); + $custom_measurement = get_post_meta($id, '_custom_measurement', true) ?: 'кг'; + if (!$product) { return ''; } if ($type == 'price') { return $product->get_price(); } elseif ($type == 'weight') { - return $product->get_weight() ? $product->get_weight() . ' кг' : ''; + return $product->get_weight() ? $product->get_weight() . ' ' . $custom_measurement : ''; } return ''; }