Retrieving the selling_plan ID dynamically to be used inside the side cart through Recharge

cedrichadjian
Excursionist
27 0 2

We need to implement a button that activates a subscription on a certain product inside the mini cart, something like a switcher.

This is the code I'm using, which works for /cart/change.js

$('#cart-item-upgrade').on("click", function(e) {
  const $this = $(this);
  const id = $this.closest('.cart-drop-item-wrapper').find('.cart-drop-item').data('variant-id');
  
  $.post('/cart/change.js', {
    id,
    selling_plan: 919371846
  })
  .always(function (data) {
    $.getJSON('/cart.js', function (cart) {
        updateCartTotal(cart.total_price);
        updateFreeShipping(cart.total_price);
        updateCartCount(cart.item_count);
        updateCart();
    });
  });
})

However, we want to make the selling_plan ID dynamically retrieved, how can we do this? We're using Recharge as our subscription provider.

Replies 0 (0)