Skip to content

selectIsDifferentShippingAddressRequired$(): Observable<boolean>

The selectIsDifferentShippingAddressRequired$ method allows to check if a different shipping address is currently required. It is helpful when we want to show something to the user if they indicate that they want to ship to a different address.

Returned value

A returned value has a type of Observable<boolean> indicating whether a different shipping addresses is currently required or not.

Example

In this example we make a basketAddressesApi call to check if a different shipping address is currently required.

useStorefront(async (storefront) => {
    let basketAddressesApi = storefront.getApiSync('basketAddressesApi');

    if (!basketAddressesApi) {
        const featureSystemApi = this.getApiSync('FeatureSystemApi');
        await featureSystemApi.registerDynamic('basket');

        basketAddressesApi = storefront.getApiSync('basketAddressesApi');
    }

    const isDifferentShippingAddressRequired$ = basketAddressesApi.selectIsDifferentShippingAddressRequired$();

    isDifferentShippingAddressRequired$.subscribe((isDifferentShippingAddressRequired) => {
        if (isDifferentShippingAddressRequired) {
            // do something if a different shipping address is required
        }
        else {
            // do something if a different shipping address is not required
        }
    })
});

Basket Address API methods reference