htdat / woo-viet

The repo for the WordPress plugin "Woo Viet - WooCommerce for Vietnam"
https://wordpress.org/plugins/woo-viet/
37 stars 22 forks source link

Removing unwanted provinces #70

Closed gallnomad closed 4 years ago

gallnomad commented 4 years ago

Hi,

I can't seem to find a way to remove provinces I don't want. We only ship to HCMC and some other closer provinces and I want to remove the rest.

Also will you be adding integration for VNPay?

Longkt commented 4 years ago

Hi,

You can add this PHP code to the file functions.php in the theme/child theme folder to add some provinces as you want

add_action( 'init', function() {
    if( class_exists( 'WooViet' ) ) {
        // Remove provinces of Viet Nam
        remove_all_filters( 'woocommerce_states');

        // Add some specific provinces
        add_filter( 'woocommerce_states', function( $states ) {
            $states['VN'] = array(
            'HO-CHI-MINH'     => __( 'Ho Chi Minh', 'woo-viet' ),
            'KHANH-HOA'       => __( 'Khanh Hoa', 'woo-viet' ),
            'KIEN-GIANG'      => __( 'Kien Giang', 'woo-viet' ),
        );

        return $states;
        } );
    }

}, 99 );
gallnomad commented 4 years ago

Awesome Long thank you so much

gallnomad commented 4 years ago

sorry could I ask you what the code would be to also exclude some districts within hcmc?

Longkt commented 4 years ago

Ok, here you are (grab the code above)

add_action( 'init', function() {
    if( class_exists( 'WooViet' ) ) {
        // Remove provinces of Viet Nam
        remove_all_filters( 'woocommerce_states');

        // Add some specific provinces
        add_filter( 'woocommerce_states', function( $states ) {
            $states['VN'] = array(
                'HO-CHI-MINH'     => __( 'Ho Chi Minh', 'woo-viet' ),
                'KHANH-HOA'       => __( 'Khanh Hoa', 'woo-viet' ),
                'KIEN-GIANG'      => __( 'Kien Giang', 'woo-viet' ),
            );

            return $states;
        } );

        // Remove cities of Viet Nam
        remove_all_filters( 'wc_city_select_cities');

        // Add specific cities
        add_filter( 'wc_city_select_cities', function( $cities ) {
            $cities['VN'] = array(
                'HO-CHI-MINH'     => array(
                    'Quận 1',
                    'Quận 10',
                    'Quận 11',
                ),
                'KHANH-HOA'       => array(
                    'Huyện Cam Lâm',
                    'Huyện Diên Khánh',
                ),
                'KIEN-GIANG'      => array(
                    'Huyện An Biên',
                    'Huyện An Minh',
                ),
            );
            return $cities;
        });
    }

}, 99 );