user3747544
user3747544

Reputation: 35

WooCommerce checkout block custom field validation

How to validate custom block field on submit in WooCommerce checkout page created with blocks?

import { useCheckoutContext } from '@woocommerce/base-contexts';
import { useEffect } from '@wordpress/element';

const Component = () => {
    const { onCheckoutValidation } = useCheckoutContext();
    useEffect( () => {
        const unsubscribe = onCheckoutValidation( () => true );
        return unsubscribe;
    }, [ onCheckoutValidation ] );
    return null;
};

I can not use import, what is the alternative of this

import { useCheckoutContext } from '@woocommerce/base-contexts';

like I can use React.useEffect() directly, not need to import { useEffect } from '@wordpress/element';

Upvotes: 0

Views: 134

Answers (0)

Related Questions