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 ' '; }); -/* Вывод пользовательских табов */ -// add_action('woocommerce_product_data_panels', function () { -// global $post; -// $feeding = get_post_meta($post->ID, '_feeding_recommendations', true); -// echo ' '; -// }); - - -// add_action('woocommerce_product_data_panels', function () { -// global $post; -// $important = get_post_meta($post->ID, '_important', true); -// 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 %}