Shopify removed this feature due to privacy reasons. Instead use the following workaround:
https://store.myshopify.com/discount/DISCOUNT_CODE?redirect=/checkout
//my example
let baseUrl = window.location.protocol + "//" + window.location.hostname;
checkout.attr('href', `${baseUrl}/discount/${discountCode}?redirect=/checkout`);