function handleClickAndScroll(cta, elementToScroll) {
  $(cta).on('click', function(event) {
    event.preventDefault();

    const targetElement = $(elementToScroll).filter(':visible');
    const stickyHeight = $('.sticky-wrapper.waypoint').outerHeight() + 20 || 0;

    $('html, body').animate({
      scrollTop: targetElement.offset().top - stickyHeight
    }, 500);
  });
}

$(document).ready(function () {
  if (!$('.pdp__main').length) {
    return;
  }

  handleClickAndScroll('.pdp-price-sale__value .pdp-price__excluding-delivery', '.pdp__fulfilment');
});
