Changeset 3253861
- Timestamp:
- 03/11/2025 08:51:23 AM (10 months ago)
- Location:
- biteship-shipping/trunk
- Files:
-
- 7 edited
-
biteship-shipping.php (modified) (2 diffs)
-
includes/class-biteship-api.php (modified) (2 diffs)
-
includes/class-biteship-helper.php (modified) (1 diff)
-
includes/class-biteship-integration.php (modified) (1 diff)
-
public/class-biteship-public.php (modified) (6 diffs)
-
public/js/checkout-modifier.js (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
biteship-shipping/trunk/biteship-shipping.php
r3250057 r3253861 4 4 * Plugin Name: Biteship Shipping 5 5 * Description: Integrate Biteship shipping services with your WooCommerce store. 6 * Version: 1. 0.106 * Version: 1.1.0 7 7 * Author: Biteship 8 8 * Author URI: https://biteship.com … … 27 27 if (in_array("woocommerce/woocommerce.php", apply_filters("active_plugins", get_option("active_plugins")))) { 28 28 // Define plugin constants. 29 define("BITESHIP_SHIPPING_VERSION", "1. 0.10");29 define("BITESHIP_SHIPPING_VERSION", "1.1.0"); 30 30 define("BITESHIP_SHIPPING_FILE", __FILE__); 31 31 define("BITESHIP_SHIPPING_PATH", plugin_dir_path(__FILE__)); -
biteship-shipping/trunk/includes/class-biteship-api.php
r3216259 r3253861 219 219 "active" => $response["data"]["active"], 220 220 "due_at" => $response["data"]["dueAt"], 221 "status" => $response["data"]["status"], 221 222 ]; 222 223 } … … 238 239 239 240 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); 240 263 } 241 264 -
biteship-shipping/trunk/includes/class-biteship-helper.php
r3250044 r3253861 38 38 $subscription_type = self::get_setting("subscription_type"); 39 39 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"; 40 46 } 41 47 -
biteship-shipping/trunk/includes/class-biteship-integration.php
r3216259 r3253861 58 58 "type" => "checkbox", 59 59 "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"), 60 67 "desc_tip" => false, 61 68 "default" => "", -
biteship-shipping/trunk/public/class-biteship-public.php
r3216259 r3253861 3 3 class Biteship_Public 4 4 { 5 private $api; 6 5 7 public function init() 6 8 { 9 $this->load_dependencies(); 7 10 $this->register_hooks(); 11 } 12 13 private function load_dependencies() 14 { 15 $this->api = Biteship_API::get_instance(); 8 16 } 9 17 … … 19 27 add_action("woocommerce_checkout_create_order_shipping_item", [$this, "enrich_shipping_method"], 10, 3); 20 28 // 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"]); 22 31 // Inject Javascript 23 add_action("wp_enqueue_scripts", [$this, "enqueue_ assets"]);32 add_action("wp_enqueue_scripts", [$this, "enqueue_scripts"]); 24 33 // Add tracking status to order history 25 34 add_action("woocommerce_order_details_after_order_table", [$this, "add_tracking_status_to_order"], 10, 1); … … 34 43 // Handle update order review on checkout page, happens when field is changed 35 44 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); 36 109 } 37 110 … … 60 133 } 61 134 62 public function enqueue_ assets()135 public function enqueue_scripts() 63 136 { 64 137 if (!is_checkout()) { … … 80 153 wp_localize_script("checkout-modifier", "phpVars", array( 81 154 "useMapForAddress" => Biteship_Helper::get_setting("use_map_for_address"), 155 "useAreaDropdown" => Biteship_Helper::get_setting("use_area_dropdown"), 82 156 )); 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 ]);