/** * Show one Country for Shipping Location based on IP (Geolocation) */ function mlget_woo_checkout_country( $fields ) { $geoData = WC_Geolocation::geolocate_ip(); $countries = WC()->countries->get_countries(); $fields['billing']['billing_country'] = array( 'type' => 'select', 'label' => __('Country', 'woocommerce'), 'options' => array( $geoData['country'] => $countries[$geoData['country']] ), 'class' => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ) ); $fields['shipping']['shipping_country'] = array( 'type' => 'select', 'label' => __('Country', 'woocommerce'), 'options' => array( $geoData['country'] => $countries[$geoData['country']] ), 'class' => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ) ); return $fields; } add_filter( 'woocommerce_checkout_fields' , 'mlget_woo_checkout_country' );
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter