const el = document.getElementById('post');
console.log(el.name.replace(/.+?\[(\d+)\]/, '$1'));
$('.form').on('submit', function (e) {
e.preventDefault();
const values = {};
$('.form__check').each(function () {
if ($(this).is(':checked')) {
const [name, ...keys] = $(this).attr('name').split('-');
if (name) {
(values[name] ??= []).push(keys.join('-'));
}
}
});
for (const key in values) {
$(`.inputs__value--${key}`).text(values[key].join(','));
}
});
Получить значение по ключу: attribute(myArray, myKey)
Получить ключ по номеру: myArray|keys|attribute|myKey
.gallery__item{ flex-shrink: 0; }
$data = [];
foreach ($products as $product) {
$temp = [
'product_id' => $product['product_id'],
'name' => $product['name'],
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $product['minimum'] > 0 ? $product['minimum'] : 1,
'rating' => $product['rating'],
];
$cart_products = $this->cart->getProducts();
foreach ($cart_products as $cart_product) {
if ($cart_product['id'] == $product['product_id']) {
$temp['quantity'] = $cart_product['quantity'] > 0 ? $cart_product['quantity'] : 1;
}
}
$data['products'][] = $temp;
}
$cart_products = $this->cart->getProducts();
// если ключи массива - уже столбец id, строчка не нужна
$cart_products = array_combine(array_column($cart_products, 'id'), $cart_products);
$data = [];
foreach ($products as $product) {
$data['products'][] = [
'product_id' => $product['product_id'],
'name' => $product['name'],
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $product['minimum'] > 0 ? $product['minimum'] : 1,
'rating' => $product['rating'],
'quantity' => $cart_products[$product['product_id']]['quantity'] > 0 ? $cart_products[$product['product_id']]['quantity'] : 1
];
}
$cart_products = $this->cart->getProducts();
$cart_products = array_combine(array_column($cart_products, 'id'), array_column($cart_products, 'quantity'));
$data = [];
foreach ($products as $product) {
$data['products'][] = [
'product_id' => $product['product_id'],
'name' => $product['name'],
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $product['minimum'] > 0 ? $product['minimum'] : 1,
'rating' => $product['rating'],
'quantity' => $cart_products[$product['product_id']] > 0 ? $cart_products[$product['product_id']] : 1
];
}
public function render_metabox($post)
{
$metabox_fields = $this->custom_fields_metabox();
?>
<table class="form-table custom-info">
<tbody>
<tr>
<th><?php echo $metabox_fields['price_field']['title']; ?></th>
<th><?php echo $metabox_fields['sale_field']['title']; ?></th>
</tr>
<tr>
<td><?php echo $metabox_fields['price_field']['value']; ?></td>
<td><?php echo $metabox_fields['sale_field']['value']; ?></td>
</tr>
</tbody>
<tbody>
<tr>
<th><?php echo $metabox_fields['material_field']['title']; ?></th>
<th><?php echo $metabox_fields['material_field']['value']; ?></th>
</tr>
</tbody>
<?
}
$iter = 1;
$insertRowIter = 1;
$insertRowIterEnd = 3;
while (...) {
if ($iter === $insertRowIter) {
echo '<div class="row-fluid">'; // открываем "обертку
}
// тут html document-info
if ($iter === $insertRowIterEnd) {
echo '</div>'; // закрываем
$iter = 0;
}
$iter++;
}
if ($iter !== $insertRowIterEnd) {
echo '</div>'; // закрываем если например в последней строке было на один меньше и тег был бы не закрытым
}
<?php $idx = 0; ?>
<?php $num_per_group = 3; ?>
<?php $manual_catalog_count = $manual_catalog->post_count; ?>
<div class="row-fluid">
<?php while( $manual_catalog->have_posts() ) : $manual_catalog->the_post(); ?>
<div class="span4 document-info">
<div class="-col-2 inline-block"><i class="file-big-icon-default file-big-icon-pdf"></i></div>
<div class="-col-9 inline-block"><a href="" target="_blank"></a>
<div class="infoDigits"><b></b>, </div>
</div>
</div>
<?php echo (++$idx) % $num_per_group == 0 ? '</div> <div class="row-fluid">' : '' ?>
<?php endwhile; ?>
</div>