• Resolved willingtonlss

    (@willingtonlss)


    Hi all, I need with creating a shipping extension. I need to limit the number of states, zones, regions or provinces we service under a specific country. At the moment I can only limit according to the country. I have this in my php file:

    public function __construct() {
        $this->id = 'tiki_lite';
        $this->method_title = __('Tiki Local Delivery');
        $this->method_description = __('Custom local delivery method for Tiki Lite');
        $this->availability = 'including';
        $this->countries = array(
            'ZA',
            'ES',
            'US',
            'GB'
        );
        $this->init();
        $this->enabled = isset($this->settings['enabled']) ? $this->settings['enabled'] : 'yes';
        $this->title = isset($this->settings['title']) ? $this->settings['title'] : __('Tiki Local Delivery', 'tiki_lite');
    }

    which works fine for limiting the country. But I tried to use this:

    public function __construct() {
        $this->id = 'tiki_lite';
        $this->method_title = __('Tiki Local Delivery');
        $this->method_description = __('Custom local delivery method for Tiki Lite');
        // Contreis availability
        $this->availability = 'including';
        $this->countries = array(
            'ZA',
            'ES',
            'US',
            'GB'
        );
        $this->states['ZA'] = array(
            'GP' => __( 'Gauteng', 'Tiki Lite' )
        );
        $this->init();
        $this->enabled = isset($this->settings['enabled']) ? $this->settings['enabled'] : 'yes';
        $this->title = isset($this->settings['title']) ? $this->settings['title'] : __('Tiki Local Delivery', 'tiki_lite');
    }

    and it made no difference. I then tried the following code:

    add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
    
    function custom_woocommerce_states( $states ) {
        $states['ZA'] = array(
            'GP' => __( 'Gauteng', 'tiki_lite' )
        );
        return $states;
    }

    which just limited the allowed shipping states for the whole of WooCommerce. I want users to be able to choose states, then for the extension to disable the extension if the chosen state is not a state we serve.

    • This topic was modified 3 years, 6 months ago by willingtonlss.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey @willingtonlss,

    I need to limit the number of states, zones, regions or provinces we service under a specific country. At the moment I can only limit according to the country.

    I understand you need helping limiting shipping methods to specifics states/ regions in a custom extension you’re developing.

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Kind regards,

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    This thread has been inactive for a while, so I’m going to mark it as resolved now. Hopefully, you’ve been able to find inputs on the above resources shared by my colleague.

    Please feel free to open a new thread if you have any further questions.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Shipping Extension Zones’ is closed to new replies.