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

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

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

@ -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 '<div id="composition_product_data" class="panel woocommerce_options_panel">';
woocommerce_wp_textarea_input([
'id' => '_composition',
'label' => 'Состав',
'desc_tip' => true,
'description' => 'Введите состав товара',
'value' => $composition
'value' => $composition // вывести значения из БД в поле
]);
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;
// $important = get_post_meta($post->ID, '_important', true);
// echo '<div id="important_product_data" class="panel woocommerce_options_panel">';
// woocommerce_wp_textarea_input([
// 'id' => '_important',
// 'label' => 'Важно',
// 'desc_tip' => true,
// 'description' => 'Введите важную информацию',
// '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,
/* Добавил пользовательское поле "Объем" во вкладку "Доставка" */
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']));
}
});
/**

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

Loading…
Cancel
Save