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