Task 6913 | Исправил вывод вариантов в карточке товара. Добавил доп поле для кастомного размера не связанное с "Вес"

pull/36/head
parent 4faac3ec34
commit b7312ebf1b
  1. 2
      wp-content/themes/cosmopet/modules/shop/components/catalog/assets/js/gp-main.js
  2. 35
      wp-content/themes/cosmopet/temp-functions/custom-admin-panel-logic.php
  3. 14
      wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php
  4. 2
      wp-content/themes/cosmopet/templates/_pages/shop/product-single.twig

@ -53,7 +53,7 @@ jQuery(document).ready(function ($) {
window.t = product.find('.product-item-overlay__price-val') window.t = product.find('.product-item-overlay__price-val')
console.log(t) console.log(t)
var new_price = price * Number(qty) 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('.select__state').data('product_price', price).data('product_id', id).val($(this).text().trim());
product.find('.state__block').removeClass('expanded').css('height', '0'); product.find('.state__block').removeClass('expanded').css('height', '0');

@ -39,33 +39,33 @@ add_action('woocommerce_product_data_panels', function () {
/* Добавил пользовательское поле "Объем" во вкладку "Доставка" */ /* Добавил пользовательское поле "Объем" во вкладку "Доставка" */
add_action('woocommerce_product_options_dimensions', function () { add_action('woocommerce_product_options_dimensions', function () {
global $post; global $post;
// $val = get_post_meta($post->ID, '_volume', true); // получить значения сохраненные в БД
// woocommerce_wp_text_input( // Поле: единица измерения (для "Вес")
// array( $val_measurement = get_post_meta($post->ID, '_custom_measurement', true);
// 'id' => '_volume',
// 'label' => 'Объем (мл)',
// 'placeholder' => 'Отобразится вместо "Вес"',
// 'desc_tip' => true,
// 'description' => 'Будет выводится вместо веса, если заполнить',
// 'value' => $val // вывести значения из БД в поле
// )
// );
// НА будуще если понадобится выпадающий список сделать для выбора единицы измерения
$val = get_post_meta($post->ID, '_custom_measurement', true); // получить значения сохраненные в БД
woocommerce_wp_select( woocommerce_wp_select(
array( array(
'id' => '_custom_measurement', 'id' => '_custom_measurement',
'label' => 'Ед. измерения (для "Вес")', 'label' => 'Ед. измерения (будет отображаться в карточке товара если Вес товара не равен значению - заполнять значение размера в "Размер для отображения")',
'description' => 'Выбранная единица измерения будет выводится вместо кг', 'description' => 'Выбранная единица измерения будет выводится вместо кг',
'desc_tip' => true, 'desc_tip' => true,
'options' => array( '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'])) { if (isset($_POST['_custom_measurement'])) {
update_post_meta($post_id, '_custom_measurement', sanitize_textarea_field($_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']));
}
}); });
/** /**

@ -98,15 +98,21 @@ function get_product_info ($id, $type) {
} }
$product = wc_get_product($id); $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) { if (!$product) {
return ''; return '';
} }
if ($type == 'price') { if ($type == 'price') {
return $product->get_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 ''; return '';
} }

@ -138,7 +138,7 @@
data-product_id="{{ sibling.ID }}" data-product_id="{{ sibling.ID }}"
data-product_price="{{ product_price }}" data-product_price="{{ product_price }}"
> >
{{ product_weight|upper }} {{ weight|upper }}
</a> </a>
{% endfor %} {% endfor %}
<input type="text" class="radio-button__input" value="{{ current_weight|upper }}" readonly> <input type="text" class="radio-button__input" value="{{ current_weight|upper }}" readonly>

Loading…
Cancel
Save