Task 5453 | вывел в админке выпадающий список с выбором ед.измерения, которая при заполнении выводится вместо КГ на подробной странице и в листинге товаров

pull/36/head
parent 413728f3d9
commit beffd44cb9
  1. 5
      wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php
  2. 7
      wp-content/themes/cosmopet/modules/shop/module-controller.php
  3. 49
      wp-content/themes/cosmopet/temp-functions/custom-admin-panel-logic.php
  4. 5
      wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php

@ -51,11 +51,6 @@ if (function_exists('is_product') && is_product()) {
}
}
// echo '<pre>';
// var_dump($attributes);
// print_r($attributes);
// echo '</pre>';
// die();
$context_for_twig['product_attributes'] = $attributes;

@ -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 '<pre>';
// print_r($product->get_price());
// echo '</pre>';
// 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');

@ -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']));
}
});

@ -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 '';
}

Loading…
Cancel
Save