For discussing the development and usage of Checkout UI extensions, post-purchase extensions, web pixels, Customer Accounts UI extensions, and POS UI extensions
how to get customer email in checkout extensions ?
const { buyerIdentity: { customer }, selectedPaymentOptions } = useApi(); console.log("email"); console.log(customer.email);
Solved! Go to the solution
This is an accepted solution.
As far as I can tell, buyerIdentity.customer is only defined when the user is logged in - if that isn't the desired behaviour, you could use buyerIdentity.email instead.
Either way, you need to subscribe to the value. This is how I did it in React:
const { buyerIdentity } = useApi();
const [email, setEmail] = useState(buyerIdentity.customer.current?.email);
useEffect(() => {
buyerIdentity.customer.subscribe(value => setEmail(value.email));
}, [buyerIdentity]);
const { buyerIdentity } = useApi();
const [email, setEmail] = useState(buyerIdentity.email.current);
useEffect(() => {
buyerIdentity.email.subscribe(value => setEmail(value.email));
}, [buyerIdentity]);
This is an accepted solution.
As far as I can tell, buyerIdentity.customer is only defined when the user is logged in - if that isn't the desired behaviour, you could use buyerIdentity.email instead.
Either way, you need to subscribe to the value. This is how I did it in React:
const { buyerIdentity } = useApi();
const [email, setEmail] = useState(buyerIdentity.customer.current?.email);
useEffect(() => {
buyerIdentity.customer.subscribe(value => setEmail(value.email));
}, [buyerIdentity]);
const { buyerIdentity } = useApi();
const [email, setEmail] = useState(buyerIdentity.email.current);
useEffect(() => {
buyerIdentity.email.subscribe(value => setEmail(value.email));
}, [buyerIdentity]);