Help, please, with Cart page promo codes

I would like to add a drop-down box to my cart page with a list of zip codes that will qualify the user for a coupon for free shipping. But I would like to have the coupon be added to the promo box by the code attached to the change event for the drop-down box… I’ve got the drop-down box in place and populated it with the zip codes, I’ve created the coupon for free shipping that works if the user types it in, but I can’t figure out how to add the promo code by javascript. Can anyone help?

Don’t think you will be able to change the promo code section on the Wix Stores Cart page, as the page itself is automatically set up for you and the promo code entry input can only be edited so much as shown in the Wix Stores section in the support pages.
https://support.wix.com/en/article/customizing-your-wix-stores-cart-page
https://support.wix.com/en/article/customizing-the-promo-code-link-on-your-wix-stores-cart-page
https://support.wix.com/en/article/about-wix-stores-coupons

I would suggest that you would be better suited contacting Wix Support to see if you can actually connect your dropdown to the promo code input to begin with before trying to achieve it in code.
https://support.wix.com/en/article/contacting-wix-support

If it can then you would simply need to take the resulting dropdown value from the users given options and insert it into the promo input.

You can have a look through the code in the Wix API sections.
https://www.wix.com/corvid/reference/wix-marketing-backend.coupons.html
https://www.wix.com/corvid/reference/$w.CartIcon.html
https://www.wix.com/corvid/reference/wix-stores.html
https://www.wix.com/corvid/reference/wix-stores-backend.html
https://www.wix.com/corvid/reference/wix-stores-backend.html#AppliedCoupon

Thanks. I’ll look through your references. I’m not actually looking to tie the dropdown box value to the promo code. It’s just that the promo code for free shipping is only offered to users who live in certain zip codes that populate the dropdown box. I’d like to enter the promo code if they are eligible and block it if they aren’t.

Can someone help me with this code???

//This is the backend
import wixStores from ‘wix-stores-backend’;
import wixMarketing from ‘wix-marketing-backend’;

export async function getFreeShipping(ZIP, selectedIndex) {
console.log('ZIP = ’ + ZIP);
const cart = await wixStores.getCurrentCart();
console.log('cart = ’ + cart);
console.log('coupon = ’ + await cart.AppliedCoupon);
const coupon = await cart.AppliedCoupon;
if (ZIP !== null && ZIP !== ‘invalidZIP’ && selectedIndex !== 0){
cart.AppliedCoupon = {
“name”: “DES MOINES”,
“code”: “DES MOINES”,
“startTime”: new Date(),
“freeShipping”: true
}
}
console.log('coupon = ’ + cart.AppliedCoupon);
return cart.AppliedCoupon;
}

THIS IS THE CART PAGE Client side codeimport {getFreeShipping} from ‘backend/cartPage.jsw’;
import {getCouponID} from ‘backend/cartPage.jsw’;

$w.onReady(async function () {
console.log(‘shoppingCart1 type = ’ + $w(“#shoppingCart1”).type);
console.log(‘shoppingCart1 parent = ’ + $w(“#shoppingCart1”).parent);
$w(’#cbValidZip’).options = [
{‘label’: ‘Not on this list’, ‘value’: ‘invalidZIP’},
{‘label’: ‘50001’, ‘value’: ‘50001’},
{‘label’: ‘50007’, ‘value’: ‘50007’},
{‘label’: ‘50009’, ‘value’: ‘50009’},
{‘label’: ‘50010’, ‘value’: ‘50010’},
{‘label’: ‘50014’, ‘value’: ‘50014’},
{‘label’: ‘50023’, ‘value’: ‘50023’},
{‘label’: ‘50027’, ‘value’: ‘50027’},
{‘label’: ‘50046’, ‘value’: ‘50046’},
{‘label’: ‘50047’, ‘value’: ‘50047’},
{‘label’: ‘50063’, ‘value’: ‘50063’},
{‘label’: ‘50073’, ‘value’: ‘50073’},
{‘label’: ‘50111’, ‘value’: ‘50111’},
{‘label’: ‘50124’, ‘value’: ‘50124’},
{‘label’: ‘50125’, ‘value’: ‘50125’},
{‘label’: ‘50131’, ‘value’: ‘50131’},
{‘label’: ‘50134’, ‘value’: ‘50134’},
{‘label’: ‘50138’, ‘value’: ‘50138’},
{‘label’: ‘50139’, ‘value’: ‘50139’},
{‘label’: ‘50161’, ‘value’: ‘50161’},
{‘label’: ‘50166’, ‘value’: ‘50166’},
{‘label’: ‘50201’, ‘value’: ‘50201’},
{‘label’: ‘50228’, ‘value’: ‘50228’},
{‘label’: ‘50237’, ‘value’: ‘50237’},
{‘label’: ‘50240’, ‘value’: ‘50240’},
{‘label’: ‘50244’, ‘value’: ‘50244’},
{‘label’: ‘50263’, ‘value’: ‘50263’},
{‘label’: ‘50310’, ‘value’: ‘50310’},
{‘label’: ‘50311’, ‘value’: ‘50311’},
{‘label’: ‘50312’, ‘value’: ‘50312’},
{‘label’: ‘50315’, ‘value’: ‘50315’},
{‘label’: ‘50317’, ‘value’: ‘50317’},
{‘label’: ‘50320’, ‘value’: ‘50320’},
{‘label’: ‘50321’, ‘value’: ‘50321’},
{‘label’: ‘50322’, ‘value’: ‘50322’},
{‘label’: ‘50327’, ‘value’: ‘50327’}
];

$w(“#cbValidZip”).selectedIndex = 0;
$w(‘#shoppingCart1’).expand();
//debugger;
const s = await getCouponID;
console.log('couponID = ’ + s);

export function cbValidZip_change(event) {
//Add your code for this event here:
getFreeShipping($w(‘#cbValidZip’).value, $w(‘#cbValidZip’).selectedIndex);
};