PHP Classes

File: ade-custom-shipping.php

Recommend this page to a friend!
  Classes of Adeleye Ayodeji   Ade Woocommerce Custom Shipping   ade-custom-shipping.php   Download  
File: ade-custom-shipping.php
Role: Auxiliary script
Content type: text/plain
Description: Plugin script
Class: Ade Woocommerce Custom Shipping
Add custom shipping options to a WooCommerce site
Author: By
Last change: Update of ade-custom-shipping.php
Date: 1 year ago
Size: 1,760 bytes
 

Contents

Class file image Download
<?php
/**
 * Plugin Name: Ade Custom Shipping
 * Plugin URI: https://wordpress.org/plugins/ade_custom_shipping/
 * Author: Adeleye Ayodeji
 * Author URI: https://adeleyeayodeji.com
 * Description: Add shipping zones 3 levels deep for ecommerce.
 * Version: 1.1
 * License: GPL2
 * License URL: http://www.gnu.org/licenses/gpl-2.0.txt
*/

// add basic plugin security.
defined( 'ABSPATH' ) || exit;

if ( !
defined( 'ADE_CUSTOM_PLGUN_FILE' ) ) {
   
define( 'ADE_CUSTOM_PLGUN_FILE', __FILE__ );
}

add_filter( 'woocommerce_states', 'ade_custom_shipping' );
add_filter( 'woocommerce_states', 'ade_custom_shipping_gh' );

$json = json_decode(file_get_contents(plugin_dir_path( ADE_CUSTOM_PLGUN_FILE ) . 'inc/all_cities.json'));
$json_gh = json_decode(file_get_contents(plugin_dir_path( ADE_CUSTOM_PLGUN_FILE ) . 'inc/all_cities_gh.json'));


function
ade_custom_shipping( $states ) {
    global
$json;

   
$map = array();

    foreach (
$json as $city) {
        for (
$i=0; $i < count($city->lgas); $i++) {
           
$map[strtolower(str_replace(" ", "", $city->lgas[$i]))] = $city->lgas[$i] . ', '.$city->state;
        }
    }

   
$states['NG'] = $map;

    return
$states;
}

function
ade_custom_shipping_gh( $states ) {
    global
$json_gh;

   
$map = array();

    foreach (
$json_gh as $city) {
        if(
count($city->lgas) == 0){
           
$map[strtolower(str_replace(" ", "", $city->region))] = $city->region;
        }else{
            for (
$i=0; $i < count($city->lgas); $i++) {
               
$map[strtolower(str_replace(" ", "", $city->lgas[$i]))] = $city->lgas[$i] . ', '.$city->state. ', '.$city->region;
            }
        }
    }

   
$states['GH'] = $map;

    return
$states;
}

//Proudly made by Adeleye Ayodeji => adeleyeayodeji.com