показывать страну доставки по IP

PHOTO EMBED

Mon Feb 21 2022 07:57:20 GMT+0000 (Coordinated Universal Time)

Saved by @mastaklance

/**
 * 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' );
content_copyCOPY