From 413728f3d956be2213635b5a865c339efb6f505d Mon Sep 17 00:00:00 2001 From: maksim Date: Sun, 22 Jun 2025 20:24:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B0?= =?UTF-8?q?=D0=B4=D0=BC=D0=B8=D0=BD=20=D0=BF=D0=B0=D0=BD=D0=B5=D0=BB=D0=B8?= =?UTF-8?q?=20=D0=B8=20=D0=BA=D0=B0=D1=80=D1=82=D0=BE=D1=87=D0=BA=D0=B8=20?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../single-product/component-controller.php | 9 +- .../modules/shop/module-controller.php | 11 +- .../custom-admin-panel-logic.php | 107 +++++++----------- .../templates/_pages/shop/product-single.twig | 20 ++-- 4 files changed, 66 insertions(+), 81 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 e20b7b8..44fca9a 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,7 +51,12 @@ if (function_exists('is_product') && is_product()) { } } - + // echo '
';
+    // var_dump($attributes);
+    // print_r($attributes);
+    // echo '
'; + // die(); + $context_for_twig['product_attributes'] = $attributes; /* Получение вариаций товара */ @@ -89,6 +94,8 @@ if (function_exists('is_product') && is_product()) { $context_for_twig['product_meta'] = $meta_fields; + + /* Товар оформляется по подписке? */ $context_for_twig['is_subscription'] = $product->is_type( array( 'subscription', 'subscription_variation', 'variable-subscription' )) ? true : false; } diff --git a/wp-content/themes/cosmopet/modules/shop/module-controller.php b/wp-content/themes/cosmopet/modules/shop/module-controller.php index e8f01d5..c784347 100644 --- a/wp-content/themes/cosmopet/modules/shop/module-controller.php +++ b/wp-content/themes/cosmopet/modules/shop/module-controller.php @@ -136,9 +136,6 @@ function custom_checkout_button_classes( $button ) { '; return $button; - - - } add_filter( 'woocommerce_checkout_fields', 'customize_checkout_registration_fields' ); @@ -326,10 +323,16 @@ 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(); + if ($product) { $context['product'] = $product; $context['product_id'] = $product_id; + $context['product_price'] = $product->get_price(); + $context['product_weight'] = $product->get_weight() . ' кг'; $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 de655f5..c0d7ba4 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 @@ -8,92 +8,71 @@ * Start: Добавление табов и полей в стандартной форме редактирования товара Woocommerce */ - -/* Вывод пользовательского поля */ +/* Создание в форме редактирования товара Woocommerce своей вкладки и поля "Состав" */ +// Создание пользовательской вкладки "Состав" +add_filter('woocommerce_product_data_tabs', function ($tabs) { + $tabs['composition_tab'] = array( + 'label' => 'Состав', + 'target' => 'composition_product_data', + // 'target' => 'shipping_product_data', // вывело поля от Доставк в вкладку "Состав" + 'class' => array('composition'), // выводим у вкладки класс "composition_tab" + 'priority' => 60, + ); + return $tabs; +}); +// Вывод пользовательского поля в пользовательской вкладке "Состав" add_action('woocommerce_product_data_panels', function () { global $post; - $composition = get_post_meta($post->ID, '_composition', true); + $composition = get_post_meta($post->ID, '_composition', true); // получить значения сохраненные в БД echo '
'; woocommerce_wp_textarea_input([ 'id' => '_composition', 'label' => 'Состав', 'desc_tip' => true, 'description' => 'Введите состав товара', - 'value' => $composition + 'value' => $composition // вывести значения из БД в поле ]); echo '
'; }); -/* Вывод пользовательских табов */ -// add_action('woocommerce_product_data_panels', function () { -// global $post; -// $feeding = get_post_meta($post->ID, '_feeding_recommendations', true); -// echo '
'; -// woocommerce_wp_textarea_input([ -// 'id' => '_feeding_recommendations', -// 'label' => 'Рекомендации по кормлению', -// 'desc_tip' => true, -// 'description' => 'Введите рекомендации по кормлению', -// 'value' => $feeding -// ]); -// echo '
'; -// }); - - -// add_action('woocommerce_product_data_panels', function () { -// global $post; -// $important = get_post_meta($post->ID, '_important', true); -// echo '
'; -// woocommerce_wp_textarea_input([ -// 'id' => '_important', -// 'label' => 'Важно', -// 'desc_tip' => true, -// 'description' => 'Введите важную информацию', -// 'value' => $important -// ]); -// echo '
'; -// }); - -// woocommerce_product_options_inventory_product_data ] -add_filter('woocommerce_product_data_tabs', function ($tabs) { - $tabs['composition_tab'] = array( - 'label' => 'Состав', - 'target' => 'composition_product_data', - 'class' => array('composition_tab'), - 'priority' => 60, +/* Добавил пользовательское поле "Объем" во вкладку "Доставка" */ +add_action('woocommerce_product_options_dimensions', function () { + woocommerce_wp_text_input( + array( + 'id' => '_volume', + 'label' => 'Объем (мл)', + 'desc_tip' => true, + 'description' => 'Выбранная единица измерения будет подставляться вместо КГ', + 'value' => 'test' // вывести значения из БД в поле + ) ); - // shipping_product_data - // shipping_options - // shipping_tab - - - // $tabs['feeding_tab'] = array( - // 'label' => 'Рекомендации по кормлению', - // 'target' => 'feeding_product_data', - // 'class' => array('feeding_tab'), - // 'priority' => 61, - // ); - // $tabs['important_tab'] = array( - // 'label' => 'Важно', - // 'target' => 'important_product_data', - // 'class' => array('important_tab'), - // 'priority' => 62, + // НА будуще если понадобится выпадающий список сделать для выбора единицы измерения + // woocommerce_wp_select( + // array( + // 'id' => '_custom_measurement', + // 'label' => 'Единица измерения (для "Вес")', + // 'description' => 'Выбранная единица измерения будет подставляться вместо КГ', + // // 'desc_tip' => true, + // 'options' => array( + // 'мм' => 'Выберите...', + // 'simple' => 'Простой', + // 'variable' => 'Вариативный', + // 'custom' => 'Пользовательский' + // ) + // ) // ); - return $tabs; }); + /* сохраненение кастомных полей */ add_action('woocommerce_process_product_meta', function ($post_id) { if (isset($_POST['_composition'])) { update_post_meta($post_id, '_composition', sanitize_textarea_field($_POST['_composition'])); } - // if (isset($_POST['_feeding_recommendations'])) { - // update_post_meta($post_id, '_feeding_recommendations', sanitize_textarea_field($_POST['_feeding_recommendations'])); - // } - // if (isset($_POST['_important'])) { - // update_post_meta($post_id, '_important', sanitize_textarea_field($_POST['_important'])); - // } + if (isset($_POST['_volume'])) { + update_post_meta($post_id, '_composition', sanitize_textarea_field($_POST['_composition'])); + } }); /** 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 8480ec1..3fe9709 100644 --- a/wp-content/themes/cosmopet/templates/_pages/shop/product-single.twig +++ b/wp-content/themes/cosmopet/templates/_pages/shop/product-single.twig @@ -83,8 +83,7 @@
- {# Start | Цена для неподписочного товара #} - + {# Start | Цена товара #} {% if not has_subscription_options and product.get_price %}
{% if is_subscription %} @@ -119,7 +118,7 @@ {% endif %}
{% endif %} - {# End | Цена для неподписочного товара #} + {# End | Цена товара #} {# Start | Кнопка добавить в корзину + варинанты подписки на товар #}
@@ -137,9 +136,9 @@ href="{{ function('get_permalink', sibling.ID) }}" class="button button--white button--red-48-px {{ class }}" data-product_id="{{ sibling.ID }}" - data-product_price="{{ function('get_product_info', sibling.ID, 'price') }}" + data-product_price="{{ product_price }}" > - {{ weight|upper }} + {{ product_weight|upper }} {% endfor %} @@ -147,21 +146,18 @@ {% endif %} {% endif %}
- {% set s_product = TimberPost(product.id) %} - - {% set s_in_stock = s_product.meta('_stock_status') == 'instock' %} + {% set s_in_stock = TimberPost(product.id).meta('_stock_status') == 'instock' %} {% if s_in_stock %} - - {{ function('do_action', 'woocommerce_' ~ product.get_type() ~ '_add_to_cart') }} - {# Start | Вывод кнопки узнать о поступлении если товара нет в наличии #} + {{ function('do_action', 'woocommerce_' ~ product.get_type() ~ '_add_to_cart') }} {% else %} + {# Start | Вывод кнопки узнать о поступлении если товара нет в наличии #}
+ {# End | Вывод кнопки узнать о поступлении если товара нет в наличии #} {% endif %} - {# End | Вывод кнопки узнать о поступлении если товара нет в наличии #} {# End | Кнопка добавить в корзину + варинанты подписки на товар #} {# Start | Табы с информацией #}