⚡ NEW: Changeset/ - HD Photos!

Changeset 3253861


Ignore:
Timestamp:
03/11/2025 08:51:23 AM (10 months ago)
Author:
biteship
Message:

Release version 1.1.0

Location:
biteship-shipping/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • biteship-shipping/trunk/biteship-shipping.php

    r3250057 r3253861  
    44 * Plugin Name: Biteship Shipping
    55 * Description: Integrate Biteship shipping services with your WooCommerce store.
    6  * Version: 1.0.10
     6 * Version: 1.1.0
    77 * Author: Biteship
    88 * Author URI: https://biteship.com
     
    2727if (in_array("woocommerce/woocommerce.php", apply_filters("active_plugins", get_option("active_plugins")))) {
    2828    // Define plugin constants.
    29     define("BITESHIP_SHIPPING_VERSION", "1.0.10");
     29    define("BITESHIP_SHIPPING_VERSION", "1.1.0");
    3030    define("BITESHIP_SHIPPING_FILE", __FILE__);
    3131    define("BITESHIP_SHIPPING_PATH", plugin_dir_path(__FILE__));
  • biteship-shipping/trunk/includes/class-biteship-api.php

    r3216259 r3253861  
    219219            "active" => $response["data"]["active"],
    220220            "due_at" => $response["data"]["dueAt"],
     221            "status" => $response["data"]["status"],
    221222        ];
    222223    }
     
    238239
    239240        return $response["api_key"];
     241    }
     242
     243    public function get_administrative_division_levels($params)
     244    {
     245        $args = [
     246            "method" => "GET",
     247            "headers" => [
     248                "Authorization" => "Bearer " . Biteship_Helper::get_setting("api_key"),
     249                "Accept" => "application/json",
     250            ],
     251        ];
     252
     253        $query_params = [
     254            'level' => $params["level"]
     255        ];
     256       
     257        if (isset($params["administrative_division_level_id"])) {
     258            $query_params['administrative_division_level_id'] = $params["administrative_division_level_id"];
     259        }
     260       
     261        $url = "/v2/woocommerce/maps/administrative_division_levels?" . http_build_query($query_params);
     262        return $this->make_request($url, $args);
    240263    }
    241264
  • biteship-shipping/trunk/includes/class-biteship-helper.php

    r3250044 r3253861  
    3838        $subscription_type = self::get_setting("subscription_type");
    3939        return $subscription_type == "woocommercePremium";
     40    }
     41
     42    public static function use_area_dropdown()
     43    {
     44        $use_area_dropdown = self::get_setting("use_area_dropdown");
     45        return $use_area_dropdown === "yes";
    4046    }
    4147
  • biteship-shipping/trunk/includes/class-biteship-integration.php

    r3216259 r3253861  
    5858                    "type" => "checkbox",
    5959                    "description" => __("Automatically fill-out necessary data for billing / shipping address based on map location.", "biteship-shipping"),
     60                    "desc_tip" => false,
     61                    "default" => "",
     62                ],
     63                "use_area_dropdown" => [
     64                    "title" => __("Use area dropdowns in checkout", "biteship-shipping"),
     65                    "type" => "checkbox",
     66                    "description" => __("Select province, city, and postcode through dropdowns in checkout page.", "biteship-shipping"),
    6067                    "desc_tip" => false,
    6168                    "default" => "",
  • biteship-shipping/trunk/public/class-biteship-public.php

    r3216259 r3253861  
    33class Biteship_Public
    44{
     5    private $api;
     6
    57    public function init()
    68    {
     9        $this->load_dependencies();
    710        $this->register_hooks();
     11    }
     12
     13    private function load_dependencies()
     14    {
     15        $this->api = Biteship_API::get_instance();
    816    }
    917
     
    1927        add_action("woocommerce_checkout_create_order_shipping_item", [$this, "enrich_shipping_method"], 10, 3);
    2028        // Add new checkout field
    21         add_action("woocommerce_checkout_fields", [$this, "coordinate_fields"]);
     29        add_action("woocommerce_checkout_fields", [$this, "add_custom_checkout_fields"], 20);
     30        add_filter("woocommerce_default_address_fields", [$this, "change_priority_of_checkout_fields"]);       
    2231        // Inject Javascript
    23         add_action("wp_enqueue_scripts", [$this, "enqueue_assets"]);
     32        add_action("wp_enqueue_scripts", [$this, "enqueue_scripts"]);
    2433        // Add tracking status to order history
    2534        add_action("woocommerce_order_details_after_order_table", [$this, "add_tracking_status_to_order"], 10, 1);
     
    3443        // Handle update order review on checkout page, happens when field is changed
    3544        add_action("woocommerce_checkout_update_order_review", [$this, "handle_update_order_review"], 10, 1);
     45        // Add Proxy API for AJAX calls for logged in users.
     46        add_action('wp_ajax_get_adm_lvl_1', [$this, 'handle_get_adm_lvl_1']);
     47        add_action('wp_ajax_get_adm_lvl_2', [$this, 'handle_get_adm_lvl_2']);
     48        add_action('wp_ajax_get_adm_lvl_3', [$this, 'handle_get_adm_lvl_3']);
     49        // Add Proxy API for AJAX calls for non logged in users.
     50        add_action('wp_ajax_nopriv_get_adm_lvl_1', [$this, 'handle_get_adm_lvl_1']);
     51        add_action('wp_ajax_nopriv_get_adm_lvl_2', [$this, 'handle_get_adm_lvl_2']);
     52        add_action('wp_ajax_nopriv_get_adm_lvl_3', [$this, 'handle_get_adm_lvl_3']);
     53
     54        // Add action to update order meta when checkout is updated
     55        add_filter('woocommerce_process_checkout_field_billing_city', [$this, "process_checkout_field_billing_city"]);
     56    }
     57
     58    public function process_checkout_field_billing_city($city) {
     59        if (!Biteship_Helper::use_area_dropdown()) {
     60            return $city;
     61        }
     62
     63        if (!empty($_POST['billing_city_name'])) {
     64            // billing_city_name is a hidden field that stores the city name (the label from the city dropdown).
     65            return sanitize_text_field($_POST['billing_city_name']);
     66        }
     67
     68        return $city;
     69    }
     70
     71    public function handle_get_adm_lvl_1()
     72    {
     73        $params = [
     74            "level" => 1
     75        ];
     76        $data = $this->api->get_administrative_division_levels($params);
     77        wp_send_json_success($data);
     78    }
     79
     80    public function handle_get_adm_lvl_2()
     81    {
     82        $woo_state_id = isset($_POST['woo_state_id']) ? sanitize_text_field($_POST['woo_state_id']) : '';
     83        $administrative_division_level_1_id = isset($_POST['administrative_division_level_1_id']) ? sanitize_text_field($_POST['administrative_division_level_1_id']) : '';
     84        if (empty($woo_state_id) && empty($administrative_division_level_1_id)) {
     85            wp_send_json_error(['message' => 'Province is required.']);
     86        }
     87
     88        $params = [
     89            "level" => 2,
     90            "administrative_division_level_id" => $woo_state_id
     91        ];
     92        $data = $this->api->get_administrative_division_levels($params); // Biteship API will convert woo state id to biteship state id
     93        wp_send_json_success($data);
     94    }
     95   
     96    public function handle_get_adm_lvl_3($administrative_division_level_2_id)
     97    {
     98        $administrative_division_level_2_id = isset($_POST['administrative_division_level_2_id']) ? sanitize_text_field($_POST['administrative_division_level_2_id']) : '';
     99        if (empty($administrative_division_level_2_id)) {
     100            wp_send_json_error(['message' => 'City is required.']);
     101        }
     102
     103        $params = [
     104            "level" => 3,
     105            "administrative_division_level_id" => $administrative_division_level_2_id
     106        ];
     107        $data = $this->api->get_administrative_division_levels($params);
     108        wp_send_json_success($data);
    36109    }
    37110
     
    60133    }
    61134
    62     public function enqueue_assets()
     135    public function enqueue_scripts()
    63136    {
    64137        if (!is_checkout()) {
     
    80153        wp_localize_script("checkout-modifier", "phpVars", array(
    81154            "useMapForAddress" => Biteship_Helper::get_setting("use_map_for_address"),
     155            "useAreaDropdown" => Biteship_Helper::get_setting("use_area_dropdown"),
    82156        ));
    83     }
    84 
    85     public function coordinate_fields($fields = [])
     157
     158        if (Biteship_Helper::use_area_dropdown()) {
     159            // Localize the script with the AJAX URL
     160            wp_localize_script('checkout-modifier', 'ajax_object', [
     161                // Maps AJAX requests to specific actions in wp_ajax_<action> and wp_ajax_nopriv_<action>. For example: wp_ajax_get_adm_lvl_1
     162                'ajax_url' => admin_url('admin-ajax.php'),
     163            ]);