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 %}