What's your biggest current challenge? Have your say in Community Polls along the right column.

How to create custom frequently bought product bundles?

How to create custom frequently bought product bundles?

Kumar2573
Shopify Partner
174 8 23
<script>
  $(document).ready(function() {
    $("input[type='checkbox']").click(function(){
      var priceTotal = 0;
        $(".list_budle input[type='checkbox']:checked").each(function() {
         var val =  $(this).attr("data-price");
    priceTotal += parseInt($(this).attr("data-price"));
    });
          var totl = parseInt(priceTotal) /100;
          var pricetVal = Intl.NumberFormat('en-US').format(totl);
          $('#get_price').text('₹'+ pricetVal);
       });
    });
</script>
{% assign FBT_Product =  product.metafields.product.frequently_bought_together.value %}
 
{% if FBT_Product != blank %}
 
<p class="inclusive">Add On</p>
    <div class="list_freq-product">
       <ul class="list_budle">
      {% for productNew in FBT_Product  %}
         <li data-id="{{productNew.first_available_variant.id}}" data-price="{{ productNew.price}}">
           <input class="meta_check" type="checkbox" data-price="{{ productNew.price }}" data-id="{{productNew.first_available_variant.id}}" value="{{ productNew.first_available_variant.id }}" style="display:block"> 
           <span>{{ productNew.title }}  <span id="adprice" data-price="{{ productNew.price |  money_without_currency }}"> {{ productNew.price | money }}</span></span>
         </li>
      {% endfor %}
      <li  style="display: none;" value="{{product.first_available_variant.id}}">
         <input class="meta_check" type="checkbox" data-id="{{product.first_available_variant.id}}" data-price="{{ product.price}}" value="{{ product.first_available_variant.id }}" checked>
      </li>
       </ul>
  </div>
 
{% endif %}



<script>
$("#atcbtn_click").click(function(event){
event.preventDefault();
//alert("click");
var atc_url = '/cart/'
$(".list_freq-product .meta_check:checked").each(function(){
atc_url = atc_url + $(this).attr('value') + ":1,"
});

//console.log("iddds",atc_url);
window.location.href = atc_url

})
</script>

Shopify Certified Developer Profile - https://www.credly.com/badges/1733d05c-2a88-490a-aef5-b01baf3b94ce/public_url
Expert Shopify Plus & shopify Developer & Theme customizer
- If the problem is solved remember to click to Accept Solution
- Press Like ?? if the answer was helpful
- Still, Facing issue, Reach out to me Email :- jitendra3496@gmail.com | Skype :- jitendra2573_1
- Direct Hire me :- Direct Contact me
Reply 1 (1)

Kumar2573
Shopify Partner
174 8 23

<script>
document.getElementById('atcbtn_click').addEventListener('click', function(event) {
event.preventDefault();
// alert("click jkk");
var dataType = [];
$(".list_freq-product .meta_check:checked").each(function() {
var data = {}; // Create a new object for each iteration
data['id'] = parseInt($(this).attr('value'));
data['quantity'] = 1;
//console.log(data);
dataType.push(data);
});
const newData = {
items : [...dataType]
}
// console.log("data",newData)
jQuery.ajax({
type: 'POST',
url: '/cart/add.js',
data: newData,
dataType: 'json',
success: function(data) {
console.log(data);
window.location.href= '/cart'
}
});
});

</script>

Shopify Certified Developer Profile - https://www.credly.com/badges/1733d05c-2a88-490a-aef5-b01baf3b94ce/public_url
Expert Shopify Plus & shopify Developer & Theme customizer
- If the problem is solved remember to click to Accept Solution
- Press Like ?? if the answer was helpful
- Still, Facing issue, Reach out to me Email :- jitendra3496@gmail.com | Skype :- jitendra2573_1
- Direct Hire me :- Direct Contact me