Правки админ панели и карточки товара

pull/36/head
parent 4e6a703392
commit 413728f3d9
  1. 7
      wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php
  2. 9
      wp-content/themes/cosmopet/modules/shop/module-controller.php
  3. 107
      wp-content/themes/cosmopet/temp-functions/custom-admin-panel-logic.php
  4. 18
      wp-content/themes/cosmopet/templates/_pages/shop/product-single.twig

@ -51,6 +51,11 @@ if (function_exists('is_product') && is_product()) {
} }
} }
// echo '<pre>';
// var_dump($attributes);
// print_r($attributes);
// echo '</pre>';
// die();
$context_for_twig['product_attributes'] = $attributes; $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['product_meta'] = $meta_fields;
/* Товар оформляется по подписке? */ /* Товар оформляется по подписке? */
$context_for_twig['is_subscription'] = $product->is_type( array( 'subscription', 'subscription_variation', 'variable-subscription' )) ? true : false; $context_for_twig['is_subscription'] = $product->is_type( array( 'subscription', 'subscription_variation', 'variable-subscription' )) ? true : false;
} }

@ -136,9 +136,6 @@ function custom_checkout_button_classes( $button ) {
<button type="submit" class="button alt button--gradient button--high button--100-perc" name="woocommerce_checkout_place_order" id="place_order" value="Оплатить" data-value="Оплатить"><span>Оплатить</span></button> <button type="submit" class="button alt button--gradient button--high button--100-perc" name="woocommerce_checkout_place_order" id="place_order" value="Оплатить" data-value="Оплатить"><span>Оплатить</span></button>
</div>'; </div>';
return $button; return $button;
} }
add_filter( 'woocommerce_checkout_fields', 'customize_checkout_registration_fields' ); 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()) { if (function_exists('is_product') && is_product()) {
$product_id = get_the_ID(); $product_id = get_the_ID();
$product = wc_get_product($product_id); $product = wc_get_product($product_id);
// echo '<pre>';
// print_r($product->get_price());
// echo '</pre>';
// die();
if ($product) { if ($product) {
$context['product'] = $product; $context['product'] = $product;
$context['product_id'] = $product_id; $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'); $terms = get_the_terms($product_id, 'product_cat');

@ -8,92 +8,71 @@
* Start: Добавление табов и полей в стандартной форме редактирования товара Woocommerce * 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 () { add_action('woocommerce_product_data_panels', function () {
global $post; global $post;
$composition = get_post_meta($post->ID, '_composition', true); $composition = get_post_meta($post->ID, '_composition', true); // получить значения сохраненные в БД
echo '<div id="composition_product_data" class="panel woocommerce_options_panel">'; echo '<div id="composition_product_data" class="panel woocommerce_options_panel">';
woocommerce_wp_textarea_input([ woocommerce_wp_textarea_input([
'id' => '_composition', 'id' => '_composition',
'label' => 'Состав', 'label' => 'Состав',
'desc_tip' => true, 'desc_tip' => true,
'description' => 'Введите состав товара', 'description' => 'Введите состав товара',
'value' => $composition 'value' => $composition // вывести значения из БД в поле
]); ]);
echo '</div>'; echo '</div>';
}); });
/* Вывод пользовательских табов */
// add_action('woocommerce_product_data_panels', function () {
// global $post;
// $feeding = get_post_meta($post->ID, '_feeding_recommendations', true);
// echo '<div id="feeding_product_data" class="panel woocommerce_options_panel">';
// woocommerce_wp_textarea_input([
// 'id' => '_feeding_recommendations',
// 'label' => 'Рекомендации по кормлению',
// 'desc_tip' => true,
// 'description' => 'Введите рекомендации по кормлению',
// 'value' => $feeding
// ]);
// echo '</div>';
// });
// add_action('woocommerce_product_data_panels', function () { /* Добавил пользовательское поле "Объем" во вкладку "Доставка" */
// global $post; add_action('woocommerce_product_options_dimensions', function () {
// $important = get_post_meta($post->ID, '_important', true); woocommerce_wp_text_input(
// echo '<div id="important_product_data" class="panel woocommerce_options_panel">'; array(
// woocommerce_wp_textarea_input([ 'id' => '_volume',
// 'id' => '_important', 'label' => 'Объем (мл)',
// 'label' => 'Важно', 'desc_tip' => true,
// 'desc_tip' => true, 'description' => 'Выбранная единица измерения будет подставляться вместо КГ',
// 'description' => 'Введите важную информацию', 'value' => 'test' // вывести значения из БД в поле
// 'value' => $important )
// ]);
// echo '</div>';
// });
// 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,
); );
// shipping_product_data // НА будуще если понадобится выпадающий список сделать для выбора единицы измерения
// shipping_options // woocommerce_wp_select(
// shipping_tab // array(
// 'id' => '_custom_measurement',
// 'label' => 'Единица измерения (для "Вес")',
// $tabs['feeding_tab'] = array( // 'description' => 'Выбранная единица измерения будет подставляться вместо КГ',
// 'label' => 'Рекомендации по кормлению', // // 'desc_tip' => true,
// 'target' => 'feeding_product_data', // 'options' => array(
// 'class' => array('feeding_tab'), // 'мм' => 'Выберите...',
// 'priority' => 61, // 'simple' => 'Простой',
// ); // 'variable' => 'Вариативный',
// $tabs['important_tab'] = array( // 'custom' => 'Пользовательский'
// 'label' => 'Важно', // )
// 'target' => 'important_product_data', // )
// 'class' => array('important_tab'),
// 'priority' => 62,
// ); // );
return $tabs;
}); });
/* сохраненение кастомных полей */ /* сохраненение кастомных полей */
add_action('woocommerce_process_product_meta', function ($post_id) { add_action('woocommerce_process_product_meta', function ($post_id) {
if (isset($_POST['_composition'])) { if (isset($_POST['_composition'])) {
update_post_meta($post_id, '_composition', sanitize_textarea_field($_POST['_composition'])); update_post_meta($post_id, '_composition', sanitize_textarea_field($_POST['_composition']));
} }
// if (isset($_POST['_feeding_recommendations'])) { if (isset($_POST['_volume'])) {
// update_post_meta($post_id, '_feeding_recommendations', sanitize_textarea_field($_POST['_feeding_recommendations'])); update_post_meta($post_id, '_composition', sanitize_textarea_field($_POST['_composition']));
// } }
// if (isset($_POST['_important'])) {
// update_post_meta($post_id, '_important', sanitize_textarea_field($_POST['_important']));
// }
}); });
/** /**

@ -83,8 +83,7 @@
<div class="swiper-pagination"></div> <div class="swiper-pagination"></div>
</div> </div>
{# Start | Цена для неподписочного товара #} {# Start | Цена товара #}
{% if not has_subscription_options and product.get_price %} {% if not has_subscription_options and product.get_price %}
<div class="detail__block-price"> <div class="detail__block-price">
{% if is_subscription %} {% if is_subscription %}
@ -119,7 +118,7 @@
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}
{# End | Цена для неподписочного товара #} {# End | Цена товара #}
{# Start | Кнопка добавить в корзину + варинанты подписки на товар #} {# Start | Кнопка добавить в корзину + варинанты подписки на товар #}
<form action="" class="detail-block__form" data-product-id="{{ product.id }}"> <form action="" class="detail-block__form" data-product-id="{{ product.id }}">
@ -137,9 +136,9 @@
href="{{ function('get_permalink', sibling.ID) }}" href="{{ function('get_permalink', sibling.ID) }}"
class="button button--white button--red-48-px {{ class }}" class="button button--white button--red-48-px {{ class }}"
data-product_id="{{ sibling.ID }}" data-product_id="{{ sibling.ID }}"
data-product_price="{{ function('get_product_info', sibling.ID, 'price') }}" data-product_price="{{ product_price }}"
> >
{{ weight|upper }} {{ product_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>
@ -147,21 +146,18 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
</form> </form>
{% set s_product = TimberPost(product.id) %} {% set s_in_stock = TimberPost(product.id).meta('_stock_status') == 'instock' %}
{% set s_in_stock = s_product.meta('_stock_status') == 'instock' %}
{% if s_in_stock %} {% if s_in_stock %}
{{ function('do_action', 'woocommerce_' ~ product.get_type() ~ '_add_to_cart') }} {{ function('do_action', 'woocommerce_' ~ product.get_type() ~ '_add_to_cart') }}
{# Start | Вывод кнопки узнать о поступлении если товара нет в наличии #}
{% else %} {% else %}
{# Start | Вывод кнопки узнать о поступлении если товара нет в наличии #}
<div class="detail-block-form__item detail-block-form__item--tn"> <div class="detail-block-form__item detail-block-form__item--tn">
<button type="button" data-pname="{{ product.title }}" class="to-know open-to-know" > <button type="button" data-pname="{{ product.title }}" class="to-know open-to-know" >
<p>{{ function('pll_e', 'Узнать о поступлении') }}</p> <p>{{ function('pll_e', 'Узнать о поступлении') }}</p>
</button> </button>
</div> </div>
{% endif %}
{# End | Вывод кнопки узнать о поступлении если товара нет в наличии #} {# End | Вывод кнопки узнать о поступлении если товара нет в наличии #}
{% endif %}
{# End | Кнопка добавить в корзину + варинанты подписки на товар #} {# End | Кнопка добавить в корзину + варинанты подписки на товар #}
{# Start | Табы с информацией #} {# Start | Табы с информацией #}

Loading…
Cancel
Save