Home / eCommerce / How to Set a Default Country on the Vendor Registration Form
Duplicate Snippet

Embed Snippet on Your Site

How to Set a Default Country on the Vendor Registration Form

Make sure to select the correct vendor registration page under WC Vendors > Settings > Registration Form.

Code Preview
php
<?php
declare(strict_types=1);
add_action(
    'wp_enqueue_scripts',
    static function () {
        $registration_page_id = (int) get_option( 'wcv_signup_registration_page_id', 0 );
        if ( 0 === $registration_page_id || ! is_page( $registration_page_id ) ) {
            return;
        }
        $default_country = 'US'; // ISO 3166-1 alpha-2 code (e.g., GB, CA, AU, …)
        wp_enqueue_script( 'wcv-signup' );
        wp_add_inline_script(
            'wcv-signup',
            sprintf(
                "window.addEventListener('load',function(){var el=document.querySelector('#wcv-registration-form select[name=\"country\"]');if(!el||el.value){return;}el.value='%s';el.dispatchEvent(new Event('change',{bubbles:true}));});",
                esc_js( $default_country )
            ),
            'after'
        );
    },
    30
);

Comments

Add a Comment