https://jsfiddle.net/d7rs49no/2/<div class="product" data-id="123">
<!-- Инфо о продукте -->
<button class="action-buy">Buy</button>
</div>
<form action="#">
<!-- Инпуты -->
<div class="visual"></div>
<input type="hidden" name="product-id" value="" />
</form>
(function($){
$(document).ready(function() {
var form = $('form');
$('.product').each(function() {
var product = $(this);
product.find('.action-buy').on('click', function() {
form.find('.visual').text(product.data('id'));
form.find('input[name=product-id]').val(product.data('id'));
})
});
});
})(jQuery);