Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
WooCommerce Plugin Development

Custom Checkout Validation

Validate custom checkout inputs before order creation.

Custom Checkout Validation — a practical guide to WooCommerce checkout validation with clear examples you can reuse in real projects.

WooCommerce Plugin Development Series (41/101). Prefer one article? Read the complete WooCommerce plugin development tutorial.

Short description

Use `woocommerce_checkout_process` and `wc_add_notice(…, 'error')` to block checkout.

Validate GSTIN

add_action('woocommerce_checkout_process', function () {
    if (empty($_POST['billing_gstin'])) {
        return;
    }
    $gstin = sanitize_text_field(wp_unslash($_POST['billing_gstin']));
    if (strlen($gstin) < 15) {
        wc_add_notice('Enter a valid GSTIN.', 'error');
    }
});

Leave a reply

Your email address will not be published. Required fields are marked *