Add a birthday form to the Rewards page

Use your theme’s form to show the birthday fields the shop collects and save the shopper’s date.

This example uses the rewards page request function and shopper ID. Enable the birthday earning rule on your test store. In this example the shop collects the month and day.

Show the birthday fields

When the signed-in shopper opens your form, read the birthday settings and saved date.

const birthdayForm = await loyalty('/customer/birthday');

If birthdayForm.enabled is true, show inputs for the month and day. Prefill them from birthdayForm.birthday when there is a saved date. Include a year input only when birthdayForm.collect_birth_year is true. Use birthdayForm.benefit for the offer text; it can describe points, a gift or no current reward. Keep the date fields available when the benefit type is none.

Save the date

Read the date from your form as numbers. For a shop collecting only the month and day, a shopper who chooses 10 June submits the following values:

const saved = await loyalty('/customer/birthday', {
	method: 'PUT',
	body: {
		customer_id: document.querySelector('[data-shopper-id]').dataset.shopperId,
		birthday: { month: 6, day: 10 }
	}
});

Show the date from saved.birthday and the balance from saved.points_balance. Reopen the form: the saved date should still be 10 June. Saving a date does not itself award birthday points or a gift. Customer and birthday reference