• Resolved Martijn

    (@ximie90)


    We use Woocommerce for a restaurant were visitors can pre-order pickups and order food to be delivered. They limit their deliveries to 1 country and 1 province, since they are on an island and the whole island is part in the same province. we can set and limit the deliveries to this province with a plugin but the checkout fields are not changed by this plugin, did not expect this. It actually requires those fields to check if the delivery is in the allowed area.

    We already set the shop to limit it to the country. So on the checkout fields, we see ‘country’ as an input area, but it is read only and pre filled with the country.

    We basicly want the same for the province.

    But we are unable to. There are plugins or custom codes we found that either hide the field, remove it or rename it. But all these break the other plugins that rely on that field to be filled.

    Is there a way to change this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Ross V. a11n

    (@rossviviano)

    Automattic Happiness Engineer

    Hi there,

    I found this snippet and tested it on my site – it works as expected for me. You’ll need to edit the snippet to add the correct country/ state codes.
    To be safe, enter the following into a Code Snippets plugin.

    // default checkout country
    add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' );
    add_filter( 'default_checkout_shipping_country', 'change_default_checkout_country' );
    function change_default_checkout_country() {
        return 'PK'; // country code
    }
    
    // default checkout state
    add_filter( 'default_checkout_billing_state', 'change_default_checkout_state' );
    add_filter( 'default_checkout_shipping_state', 'change_default_checkout_state' );
    function change_default_checkout_state() {
        return 'SD'; // state code
    }
    
    // Setting one state only
    add_filter( 'woocommerce_states', 'custom_woocommerce_state', 10, 1 );
    function custom_woocommerce_state( $states ) {
        // Returning a unique state
        return array('PK' => array('SD' => 'Sindh'));
    }
    
    // Only one country at checkout
    add_filter( 'woocommerce_checkout_fields', 'custom_checkout_fields', 10, 1 );
    function custom_checkout_fields( $fields ) {
    
        $fields['billing']['billing_city']['type'] = 'select';
        $fields['billing']['billing_city']['options'] = array('Karachi' => 'Karachi');
        $fields['shipping']['shipping_city']['type'] = 'select';
        $fields['shipping']['shipping_city']['options'] = array('Karachi' => 'Karachi');
    
        return $fields;
    }
    Plugin Support abwaita a11n

    (@abwaita)

    Hi @ximie90,

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. Hopefully, the above snippet was helpful!

    If you have further questions, please feel free to open a new topic.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘We can set the country but not the province’ is closed to new replies.