Changeset 3255662
- Timestamp:
- 03/14/2025 03:15:17 AM (13 months ago)
- Location:
- sendbox-shipping
- Files:
-
- 46 added
- 5 edited
-
tags/5.2 (added)
-
tags/5.2/LICENSE.txt (added)
-
tags/5.2/README.md (added)
-
tags/5.2/README.txt (added)
-
tags/5.2/admin (added)
-
tags/5.2/admin/class-wooss-admin.php (added)
-
tags/5.2/admin/css (added)
-
tags/5.2/admin/css/wooss-admin.css (added)
-
tags/5.2/admin/images (added)
-
tags/5.2/admin/images/loader.gif (added)
-
tags/5.2/admin/index.php (added)
-
tags/5.2/admin/js (added)
-
tags/5.2/admin/js/wooss-admin.js (added)
-
tags/5.2/admin/partials (added)
-
tags/5.2/admin/partials/wooss-admin-display.php (added)
-
tags/5.2/includes (added)
-
tags/5.2/includes/assets (added)
-
tags/5.2/includes/assets/css (added)
-
tags/5.2/includes/assets/css/styles.css (added)
-
tags/5.2/includes/assets/js (added)
-
tags/5.2/includes/assets/js/jqueryserilize.js (added)
-
tags/5.2/includes/assets/js/script.js (added)
-
tags/5.2/includes/class-wooss-activator.php (added)
-
tags/5.2/includes/class-wooss-deactivator.php (added)
-
tags/5.2/includes/class-wooss-i18n.php (added)
-
tags/5.2/includes/class-wooss-loader.php (added)
-
tags/5.2/includes/class-wooss-sendbox-shipping-api.php (added)
-
tags/5.2/includes/class-wooss-shipping-method.php (added)
-
tags/5.2/includes/class-wooss.php (added)
-
tags/5.2/includes/index.php (added)
-
tags/5.2/index.php (added)
-
tags/5.2/languages (added)
-
tags/5.2/languages/wooss-en_US.mo (added)
-
tags/5.2/languages/wooss-en_US.po (added)
-
tags/5.2/languages/wooss.pot (added)
-
tags/5.2/public (added)
-
tags/5.2/public/class-wooss-public.php (added)
-
tags/5.2/public/css (added)
-
tags/5.2/public/css/wooss-public.css (added)
-
tags/5.2/public/index.php (added)
-
tags/5.2/public/js (added)
-
tags/5.2/public/js/wooss-public.js (added)
-
tags/5.2/public/partials (added)
-
tags/5.2/public/partials/wooss-public-display.php (added)
-
tags/5.2/uninstall.php (added)
-
tags/5.2/wooss.php (added)
-
trunk/README.txt (modified) (1 diff)
-
trunk/admin/class-wooss-admin.php (modified) (5 diffs)
-
trunk/admin/js/wooss-admin.js (modified) (2 diffs)
-
trunk/includes/class-wooss-shipping-method.php (modified) (1 diff)
-
trunk/wooss.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sendbox-shipping/trunk/README.txt
r3255617 r3255662 5 5 Requires at least: 6.5.4 6 6 Tested up to: 6.7 7 Stable tag: 5. 17 Stable tag: 5.2 8 8 Requires PHP: 8.0 9 9 License: GPLv2 or later -
sendbox-shipping/trunk/admin/class-wooss-admin.php
r2776138 r3255662 148 148 //phpcs:disable 149 149 public function add_sendbox_metabox() { 150 if ( ! isset( $_GET['post'] ) ) { 151 return; 152 } 153 154 global $post_type; 155 if ( is_admin() && 'shop_order' == $post_type ) { 156 $order_id = $_GET['post']; 157 $_order = wc_get_order( $order_id ); 158 $method_id = ''; 159 foreach ( $_order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ) { 160 $method_id .= $shipping_item_obj->get_method_id(); 150 if ( ! is_admin() ) { 151 return; 152 } 153 154 155 if ( isset( $_GET['post'] ) ) { 156 $order_id = absint( $_GET['post'] ); 157 } elseif ( isset( $_GET['id'] ) ) { 158 $order_id = absint( $_GET['id'] ); 159 } else { 160 return; 161 } 162 163 if ( 'shop_order_placehold' !== get_post_type( $order_id ) ) { 164 return; 165 } 166 167 168 // Get the order and check shipping method(s) 169 $_order = wc_get_order( $order_id ); 170 if ( ! $_order ) { 171 return; 172 } 173 174 $method_id = ''; 175 foreach ( $_order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ) { 176 $method_id .= $shipping_item_obj->get_method_id(); 177 } 178 // If the shipping method is 'wooss', add the metabox 179 add_meta_box( 180 'wooss_ship_sendbox', 181 __( 'Ship with Sendbox' ), 182 array( $this, 'field_for_request_shipments' ), 183 get_current_screen()->id, 184 'side', 185 'high' 186 ); 187 } 188 189 190 public function field_for_request_shipments( $order ) { 191 // Use the proper getter to retrieve the order ID. 192 $order_id = $order->get_id(); 193 // Only proceed if the post type is shop_order and shipping is enabled. 194 if ( 'shop_order_placehold' !== get_post_type( $order_id ) || get_option('wooss_option_enable') === "no" ) { 195 return; 196 } 197 198 // $order is already a WC_Order object so no need to call wc_get_order() again. 199 // Get destination (customer) details. 200 201 $destination_name = $order->get_formatted_billing_full_name(); 202 $destination_phone = $order->get_billing_phone(); 203 $destination_street = $order->get_billing_address_1(); 204 $destination_city = $order->get_billing_city(); 205 $destination_state = $order->get_billing_state(); 206 $destination_country = $order->get_billing_country(); 207 $destination_email = $order->get_billing_email(); 208 209 // Use WC_Countries to resolve state name. 210 $countries_obj = new WC_Countries(); 211 $states = $countries_obj->get_states( $destination_country ); 212 213 if ( empty( $destination_state ) ) { 214 $destination_state = $destination_city; 215 } 216 if ( stripos( $destination_state, 'FC' ) !== false && ( $destination_country === 'NG' || stripos( $destination_country, 'nigeria' ) !== false ) ) { 217 $destination_state = 'abuja'; 218 } 219 // Build items list. 220 $items_lists = array(); 221 $total_fee = 0; 222 $total_quantity = 0; 223 foreach ( $order->get_items() as $item ) { 224 $product = $item->get_product(); 225 if ( ! $product ) { 226 continue; 161 227 } 162 163 if ( $method_id == 'wooss' ) { 164 add_meta_box( 'wooss_ship_sendbox', __( 'Ship with Sendbox', 'wooss' ), array( $this, 'field_for_request_shipments' ), 'shop_order', 'side', 'high' ); 165 } 166 } 167 } 168 169 public function field_for_request_shipments( $order ) { 170 global $post_type; 171 $order_id = $order->ID; 172 $shipping_methods_enabled = get_option( 'wooss_option_enable' ); 173 if ( 'shop_order' == $post_type && $shipping_methods_enabled != "no" ) { 174 $_order = new WC_Order( $order_id ); 175 $destination_name = $_order->get_formatted_billing_full_name(); 176 $destination_phone = $_order->get_billing_phone(); 177 $destination_street = $_order->get_billing_address_1(); 178 $destination_city = $_order->get_billing_city(); 179 $destination_state = $_order->get_billing_state(); 180 $destination_country = $_order->get_billing_country(); 181 $destination_email = $_order->get_billing_email(); 182 183 $countries_obj = new WC_Countries(); 184 185 $states = $countries_obj->get_states( $destination_country ); 186 foreach ( $states as $state_code => $state_name ) { 187 if ( $destination_state == $state_code ) { 188 $destination_state = $state_name; 189 break; 228 $item_data = new stdClass(); 229 $item_data->name = $item->get_name(); 230 $item_data->quantity = $item->get_quantity(); 231 $item_data->value = $product->get_price(); 232 $item_data->amount_to_receive = $product->get_price(); 233 $item_data->package_size_code = 'medium'; 234 $item_data->item_type_code = 'other'; 235 $weight = $product->get_weight() ? $product->get_weight() : 0; 236 // Multiply weight by quantity. 237 $item_data->weight = $weight * $item->get_quantity(); 238 $total_fee += round( $product->get_price() ); 239 $total_quantity += $item->get_quantity(); 240 $items_lists[] = $item_data; 241 } 242 243 // Prepare API call to get origin (store) details. 244 $api_call = new Wooss_Sendbox_Shipping_API(); 245 $auth_header = Wooss_Sendbox_Shipping_API::checkAuth(); 246 $sendbox_data = get_option('sendbox_data'); 247 $args = array( 248 'timeout' => 30, 249 'headers' => array( 250 'Content-Type' => 'application/json', 251 'Authorization' => $auth_header, 252 ), 253 ); 254 $profile_api_url = 'https://live.sendbox.co/oauth/profile'; 255 $profile_code = $api_call->get_api_response_code( $profile_api_url, $args, 'GET' ); 256 $profile_body = $api_call->get_api_response_body( $profile_api_url, $args, 'GET' ); 257 258 $wooss_origin_name = ''; 259 $wooss_origin_email = ''; 260 $wooss_origin_phone = ''; 261 $country_code_default = ''; 262 if ( $profile_code == 200 && ! empty( $profile_body ) ) { 263 $wooss_origin_name = $profile_body->name; 264 $wooss_origin_email = $profile_body->email; 265 $wooss_origin_phone = $profile_body->phone; 266 $country_code_default = isset( $profile_body->country->code ) ? $profile_body->country->code : ''; 267 } 268 269 // Get store (origin) details. 270 $wc_city = get_option( 'woocommerce_store_city' ); 271 $wc_store_address = get_option( 'woocommerce_store_address' ); 272 273 $wooss_origin_city = ! empty( $sendbox_data['wooss_city'] ) ? $sendbox_data['wooss_city'] : $wc_city; 274 $wooss_origin_street = ! empty( $sendbox_data['wooss_street'] ) ? $sendbox_data['wooss_street'] : $wc_store_address; 275 $wooss_origin_states = ! empty( $sendbox_data['wooss_state_name'] ) ? $sendbox_data['wooss_state_name'] : ''; 276 $wooss_origin_country = ! empty( $sendbox_data['wooss_country'] ) ? $sendbox_data['wooss_country'] : ''; 277 278 $wooss_pickup_type = ! empty( $sendbox_data['wooss_pickup_type'] ) ? $sendbox_data['wooss_pickup_type'] : 'pickup'; 279 $incoming_option_code = $wooss_pickup_type; 280 if ( empty( $incoming_option_code ) ) { 281 return; 282 } 283 284 // Set pickup date to tomorrow. 285 $date = new DateTime(); 286 $date->modify( '+1 day' ); 287 $pickup_date = $date->format( DateTime::ATOM ); 288 289 // Confirm the shipping method for this order is 'wooss'. 290 $method_id = ''; 291 foreach ( $order->get_items( 'shipping' ) as $shipping_item ) { 292 $method_id .= $shipping_item->get_method_id(); 293 } 294 if ( $method_id !== 'wooss' ) { 295 return; 296 } 297 298 // Build the payload for the delivery quote API. 299 $payload_data = new stdClass(); 300 $payload_data->origin_name = $wooss_origin_name; 301 $payload_data->destination_country_code = $destination_country; 302 $payload_data->destination_state = $destination_state; 303 $payload_data->destination_city = $destination_city; 304 $payload_data->destination_street = $destination_street; 305 $payload_data->destination_name = $destination_name; 306 $payload_data->destination_phone = $destination_phone; 307 $payload_data->items = $items_lists; 308 $payload_data->weight = $total_quantity * $weight; 309 $payload_data->amount_to_receive = $total_fee; 310 $payload_data->origin_country = $wooss_origin_country; 311 $payload_data->origin_state = $wooss_origin_states; 312 $payload_data->origin_phone = $wooss_origin_phone; 313 $payload_data->origin_street = $wc_store_address; 314 $payload_data->origin_city = $wooss_origin_city; 315 $payload_data->pickup_date = $pickup_date; 316 $payload_data->incoming_option_code = $incoming_option_code; 317 $payload_data->payment_option_code = 'prepaid'; 318 319 $payload_json = wp_json_encode( $payload_data ); 320 $delivery_args = array( 321 'timeout' => 30, 322 'headers' => array( 323 'Content-Type' => 'application/json', 324 'Authorization' => $auth_header, 325 ), 326 'body' => $payload_json, 327 ); 328 329 // Get shipping quote. 330 $quote_api_url = $api_call->get_sendbox_api_url( 'delivery_quote' ); 331 $quote_body = $api_call->get_api_response_body( $quote_api_url, $delivery_args, 'POST' ); 332 $quotes_rates = isset( $quote_body->rates ) ? $quote_body->rates : array(); 333 $wallet = isset( $quote_body->wallet_balance ) ? $quote_body->wallet_balance : ''; 334 335 // Build a JSON string for the items if needed. 336 $product_content = ''; 337 foreach ( $items_lists as $item ) { 338 $product_content .= sprintf( 339 '{"name": "%s", "quantity": "%s", "value": "%s", "amount_to_receive": "%s", "package_size_code": "%s", "item_type": "%s", "weight": "%s"}', 340 esc_js( $item->name ), 341 esc_js( $item->quantity ), 342 esc_js( $item->value ), 343 esc_js( $item->amount_to_receive ), 344 esc_js( $item->package_size_code ), 345 esc_js( $item->item_type_code ), 346 esc_js( $item->weight ) 347 ); 348 } 349 350 // Fetch countries for the dropdowns. 351 unset( $args['headers']['Authorization'] ); 352 $countries_api_url = add_query_arg( 'page_by', '{"per_page":264}', 'https://api.sendbox.co/auth/countries' ); 353 $countries_response = wp_remote_get( $countries_api_url, $args ); 354 $countries_body = json_decode( wp_remote_retrieve_body( $countries_response ) ); 355 $countries = ( isset( $countries_body->results ) && is_array( $countries_body->results ) ) ? $countries_body->results : array(); 356 357 // Optionally sort countries alphabetically. 358 usort( $countries, function( $a, $b ) { 359 return strcmp( $a->name, $b->name ); 360 }); 361 362 // Use output buffering to render the HTML. 363 ob_start(); 364 ?> 365 <div id="wooss_shipments_data"> 366 <!-- Hidden JSON Payload --> 367 <textarea id="wooss_payload_data" name="wooss_payload_data" style="display:none;"><?php echo esc_textarea( $payload_json ); ?></textarea> 368 369 <!-- Inline CSS for styling --> 370 <style> 371 /* Ensure fieldsets are spaced and remove default borders */ 372 #wooss_shipments_data fieldset { 373 border: none; 374 margin: 0; 375 padding: 0; 190 376 } 191 } 192 193 if ( empty( $destination_state ) ) { 194 $destination_state = 'London'; 195 } 196 197 $country = $countries_obj->get_countries(); 198 foreach ( $country as $country_code => $country_name ) { 199 if ( $destination_country == $country_code ) { 200 $destination_country = $country_code; 201 break; 377 /* Make the legend bold and a bit larger */ 378 #wooss_shipments_data legend { 379 font-weight: bold; 380 font-size: 1.2em; 381 margin-bottom: 10px; 202 382 } 203 } 204 205 $customer_products = $_order->get_items(); 206 $items_lists = array(); 207 208 $fee = 0; 209 $quantity = 0; 210 211 foreach ( $customer_products as $products_data ) { 212 $product_data = $products_data->get_data(); 213 $product_id = $product_data['product_id']; 214 $_product = wc_get_product( $product_id ); 215 $items_data = new stdClass(); 216 $items_data->name = $product_data['name']; 217 $items_data->quantity = $product_data['quantity']; 218 $items_data->value = $_product->get_price(); 219 $items_data->amount_to_receive = $_product->get_price(); 220 $items_data->package_size_code = 'medium'; 221 $items_data->item_type_code = strip_tags( wc_get_product_category_list( $product_id ) ); 222 223 $product_weight = $_product->get_weight(); 224 if ( null != $product_weight ) { 225 $weight = $product_weight; 226 } else { 227 $weight = 0; 383 /* Style for the dashed separator line */ 384 .separator { 385 border: 0; 386 border-bottom: 1px dashed #ccc; 387 margin: 20px 0; 228 388 } 229 230 $fee += round( $_product->get_price() ); 231 $quantity += $product_data['quantity']; 232 $items_data->weight = $weight * $quantity; 233 array_push( $items_lists, $items_data ); 234 } 235 236 $api_call = new Wooss_Sendbox_Shipping_API(); 237 $auth_header = Wooss_Sendbox_Shipping_API::checkAuth(); 238 $sendbox_data = get_option('sendbox_data'); 239 $args = array( 240 'timeout' => 30, 241 'headers' => array( 242 'Content-Type' => 'application/json', 243 'Authorization' => $auth_header, 244 ), 245 ); 246 $profile_api_url = 'https://live.sendbox.co/oauth/profile'; 247 $profile_data_response_code = $api_call->get_api_response_code( $profile_api_url, $args, 'GET' ); 248 $profile_data_response_body = $api_call->get_api_response_body( $profile_api_url, $args, 'GET' ); 249 $wooss_origin_name = ''; 250 $wooss_origin_email = ''; 251 $wooss_origin_phone = ''; 252 if ( 200 == $profile_data_response_code ) { 253 $wooss_origin_name = $profile_data_response_body->name; 254 $wooss_origin_email = $profile_data_response_body->email; 255 $wooss_origin_phone = $profile_data_response_body->phone; 256 //MAKEING CHANGES HERE 257 $country_code_default = $profile_data_response_body->country->code; 258 } 259 $wc_city = get_option( 'woocommerce_store_city' ); 260 $wc_store_address = get_option( 'woocommerce_store_address' ); 261 $wooss_origin_city = $sendbox_data['wooss_city']; 262 $wooss_origin_street = $sendbox_data['wooss_street']; 263 if ( ! $wooss_origin_city ) { 264 $wooss_origin_city = $wc_city; 265 } 266 if ( ! $wooss_origin_street ) { 267 $wooss_origin_street = $wc_store_address; 268 } 269 $wooss_origin_states_selected = $sendbox_data['wooss_state_name']; 270 if ( ! $wooss_origin_states_selected ) { 271 $wooss_origin_states_selected = ''; 272 } 273 $wooss_origin_country = $sendbox_data[ 'wooss_country' ]; 274 /* if ( ! $wooss_origin_country ) { 275 $wooss_origin_country = 'Nigeria'; 276 } */ 277 278 $wooss_pickup_type = $sendbox_data['wooss_pickup_type']; 279 if ( ! $wooss_pickup_type ) { 280 $wooss_pickup_type = 'pickup'; 281 } 282 283 $incoming_option_code = $sendbox_data['wooss_pickup_type']; 284 if ( ! $incoming_option_code ) { 285 return; 286 } 287 288 $date = new DateTime(); 289 $date->modify( '+1 day' ); 290 $method_id = ''; 291 $pickup_date = $date->format( DateTime::ATOM ); 292 293 $method_id = ''; 294 foreach ( $_order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ) { 295 $method_id .= $shipping_item_obj->get_method_id(); 296 } 297 298 if ( $method_id == 'wooss' ) { 299 389 /* Optional: Bold the labels in form groups */ 390 .form-group label { 391 font-weight: bold; 392 display: block; 393 margin-bottom: 5px; 394 } 395 /* Ensure inputs take full width */ 396 .wooss-text, .custom_input { 397 width: 100%; 398 box-sizing: border-box; 399 } 400 </style> 401 402 <!-- Editable Origin Details --> 403 <fieldset> 404 <legend><?php esc_html_e( 'Origin Details', 'wooss' ); ?></legend> 405 <div class="form-group" style="margin-bottom:10px;"> 406 <label for="wooss_origin_name"><?php esc_html_e( 'Name:', 'wooss' ); ?></label> 407 <input type="text" id="wooss_origin_name" name="wooss_origin_name" class="wooss-text" value="<?php echo esc_attr( $wooss_origin_name ); ?>"> 408 </div> 409 <div class="form-group" style="margin-bottom:10px;"> 410 <label for="wooss_origin_phone"><?php esc_html_e( 'Phone:', 'wooss' ); ?></label> 411 <input type="text" id="wooss_origin_phone" name="wooss_origin_phone" class="wooss-text" value="<?php echo esc_attr( $wooss_origin_phone ); ?>"> 412 </div> 413 <div class="form-group" style="margin-bottom:10px;"> 414 <label for="wooss_origin_street"><?php esc_html_e( 'Street:', 'wooss' ); ?></label> 415 <input type="text" id="wooss_origin_street" name="wooss_origin_street" class="wooss-text" value="<?php echo esc_attr( $wc_store_address ); ?>"> 416 </div> 417 <div class="form-group" style="margin-bottom:10px;"> 418 <label for="wooss_origin_state"><?php esc_html_e( 'State:', 'wooss' ); ?></label> 419 <input type="text" id="wooss_origin_state" name="wooss_origin_state" class="wooss-text" value="<?php echo esc_attr( $wooss_origin_states ); ?>"> 420 </div> 421 <div class="form-group" style="margin-bottom:10px;"> 422 <label for="wooss_origin_country"><?php esc_html_e( 'Country:', 'wooss' ); ?></label> 423 <select id="wooss_origin_country" name="wooss_origin_country" class="custom_input"> 424 <option data-country-code="default" value=""><?php _e( 'Please select origin country', 'wooss' ); ?></option> 425 <?php foreach ( $countries as $country_item ) : ?> 426 <option data-country-code="<?php echo esc_attr( $country_item->code ); ?>" value="<?php echo esc_attr( $country_item->name ); ?>" <?php selected( $wooss_origin_country, $country_item->name ); ?>> 427 <?php echo esc_html( $country_item->name ); ?> 428 </option> 429 <?php endforeach; ?> 430 </select> 431 </div> 432 <div class="form-group" style="margin-bottom:10px;"> 433 <label for="wooss_origin_city"><?php esc_html_e( 'City:', 'wooss' ); ?></label> 434 <input type="text" id="wooss_origin_city" name="wooss_origin_city" class="wooss-text" value="<?php echo esc_attr( $wooss_origin_city ); ?>"> 435 </div> 436 </fieldset> 437 438 <!-- Dashed separator --> 439 <hr class="separator"> 440 441 <!-- Destination Details (Read-Only) --> 442 <fieldset> 443 <legend><?php esc_html_e( 'Destination Details', 'wooss' ); ?></legend> 444 <div class="form-group" style="margin-bottom:10px;"> 445 <label for="wooss_destination_name"><?php esc_html_e( 'Name:', 'wooss' ); ?></label> 446 <input type="text" id="wooss_destination_name" name="wooss_destination_name" class="wooss-text" value="<?php echo esc_attr( $destination_name ); ?>" readonly> 447 </div> 448 <div class="form-group" style="margin-bottom:10px;"> 449 <label for="wooss_destination_phone"><?php esc_html_e( 'Phone:', 'wooss' ); ?></label> 450 <input type="text" id="wooss_destination_phone" name="wooss_destination_phone" class="wooss-text" value="<?php echo esc_attr( $destination_phone ); ?>" readonly> 451 </div> 452 <div class="form-group" style="margin-bottom:10px;"> 453 <label for="wooss_destination_street"><?php esc_html_e( 'Street:', 'wooss' ); ?></label> 454 <input type="text" id="wooss_destination_street" name="wooss_destination_street" class="wooss-text" value="<?php echo esc_attr( $destination_street ); ?>" readonly> 455 </div> 456 <div class="form-group" style="margin-bottom:10px;"> 457 <label for="wooss_destination_state"><?php esc_html_e( 'State:', 'wooss' ); ?></label> 458 <input type="text" id="wooss_destination_state" name="wooss_destination_state" class="wooss-text" value="<?php echo esc_attr( $destination_state ); ?>" readonly> 459 </div> 460 <div class="form-group" style="margin-bottom:10px;"> 461 <label for="wooss_destination_country"><?php esc_html_e( 'Country:', 'wooss' ); ?></label> 462 <select id="wooss_destination_country" name="wooss_destination_country" class="custom_input" disabled> 463 <option data-country-code="default" value=""><?php echo esc_html( $destination_country ); ?></option> 464 </select> </div> 465 <div class="form-group" style="margin-bottom:10px;"> 466 <label for="wooss_destination_city"><?php esc_html_e( 'City:', 'wooss' ); ?></label> 467 <input type="text" id="wooss_destination_city" name="wooss_destination_city" class="wooss-text" value="<?php echo esc_attr( $destination_city ); ?>" readonly> 468 </div> 469 <div class="form-group" style="margin-bottom:10px;"> 470 <label for="wooss_destination_email"><?php esc_html_e( 'Email:', 'wooss' ); ?></label> 471 <input type="text" id="wooss_destination_email" name="wooss_destination_email" class="wooss-text" value="<?php echo esc_attr( $destination_email ); ?>" readonly> 472 </div> 473 </fieldset> 474 475 <!-- Dashed separator --> 476 <hr class="separator"> 477 478 <!-- Shipment Details (Weight Read-Only) --> 479 <fieldset> 480 <legend><?php esc_html_e( 'Shipment Details', 'wooss' ); ?></legend> 481 <div class="form-group" style="margin-bottom:10px;"> 482 <label for="wooss_weight"><?php esc_html_e( 'Weight:', 'wooss' ); ?></label> 483 <input type="text" id="wooss_weight" name="wooss_weight" class="wooss-text" value="<?php echo esc_attr( $weight ); ?>" readonly> 484 </div> 485 <div class="form-group" style="margin-bottom:10px;"> 486 <label for="wooss_incoming_option_code"><?php esc_html_e( 'Incoming Option Code:', 'wooss' ); ?></label> 487 <input type="text" id="wooss_incoming_option_code" name="wooss_incoming_option_code" class="wooss-text" value="<?php echo esc_attr( $incoming_option_code ); ?>"> 488 </div> 489 </fieldset> 490 491 <!-- Dashed separator --> 492 <hr class="separator"> 493 <!-- Wallet Balance and Courier Selection --> 494 <div class="wooss-wallet-courier" style="margin-bottom:20px;"> 495 <div style="margin-bottom:10px;"> 496 <strong><?php esc_html_e( 'WALLET BALANCE', 'wooss' ); ?>:</strong> 497 <span><?php echo esc_html( $quote_body->rates[0]->currency . $wallet ); ?></span> 498 </div> 499 <div class="form-group" style="margin-bottom:10px;"> 500 <label for="wooss_selected_courier"><?php esc_html_e( 'Select Courier:', 'wooss' ); ?></label> 501 <select id="wooss_selected_courier" name="wooss_selected_courier"> 502 <option value=""><?php esc_html_e( 'Select a courier...', 'wooss' ); ?></option> 503 <?php foreach ( $quotes_rates as $rate ) : ?> 504 <option data-courier-price="<?php echo esc_attr( $rate->fee ); ?>" value="<?php echo esc_attr( $rate->service_code ); ?>" id="<?php echo esc_attr( $rate->courier_id ); ?>"> 505 <?php echo esc_html( $rate->name ); ?> 506 </option> 507 <?php endforeach; ?> 508 </select> 509 </div> 510 </div> 511 512 <div style="display:flex; justify-content:space-between; align-items:center;"> 513 <b id="dabs"><?php /* Optionally display fee here */ ?></b> 514 </div> 515 516 <!-- Extra Field: Postal Code and Request Shipment Button --> 517 <div class="wooss-extra-fields" style="margin-top:20px;"> 518 <?php 519 $postal_code = $order->get_billing_postcode(); 520 if ( ! empty( $postal_code ) ) { 521 echo '<div class="form-group" style="margin-bottom:10px;">'; 522 echo '<label for="wooss_postal_code">' . esc_html__( 'Postal Code:', 'wooss' ) . '</label>'; 523 echo "<input id='wooss_postal_code' type='text' value='" . esc_attr( $postal_code ) . "' placeholder='" . esc_attr__( 'Enter Postal Code', 'wooss' ) . "'>"; 524 echo '</div>'; 525 } 300 526 ?> 301 302 <div id="wooss_shipments_data"> 303 304 <span style="display:none;"><strong><?php esc_html_e( 'Origin Details : ', 'wooss' ); ?></strong> 305 <i>This represents your store details</i> 306 <br /> 307 <strong><label for="wooss_origin_name"><?php esc_html_e( 'Name : ', 'wooss' ); ?></label></strong> 308 <input type="text" name="wooss_origin_name" id="wooss_origin_name" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_name ) ); ?>" readonly> 309   310 <strong><label for="wooss_origin_phone"><?php esc_html_e( 'Phone : ', 'wooss' ); ?></label></strong> 311 <input type="text" name="wooss_origin_phone" id="wooss_origin_phone" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_phone ) ); ?>" readonly> 312 <br />  313 314 <br /><strong><label for="wooss_origin_email"><?php esc_html_e( 'Email : ', 'wooss' ); ?></label></strong> 315 <input type="text" name="wooss_origin_email" id="wooss_origin_email" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_email ) ); ?>" readonly> 316   317 <strong><label for="wooss_origin_street"><?php esc_html_e( 'Street : ', 'wooss' ); ?></label></strong> 318 <input type="text" name="wooss_origin_street" id="wooss_origin_street" class="wooss-text" class="wooss-text" value="<?php echo ( esc_attr( $wc_store_address ) ); ?>" readonly> 319 <br />  320 <br /><strong><label for="wooss_origin_country"><?php esc_html_e( 'Country : ', 'wooss' ); ?></label></strong> 321 <input type="text" name="wooss_origin_country" id="wooss_origin_country" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_country ) ); ?>" readonly> 322   323 <strong><label for="wooss_origin_state"><?php esc_html_e( 'States : ', 'wooss' ); ?></label></strong> 324 <input type="text" name="wooss_origin_state" id="wooss_origin_state" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_states_selected ) ); ?>" readonly> 325   326 327 <br />  328 329 330 <br /><strong><label for="wooss_origin_city"><?php esc_html_e( 'City : ', 'wooss' ); ?></label></strong> 331 <input type="text" name="wooss_origin_city" id="wooss_origin_city" class="wooss-text" value="<?php echo ( esc_attr( $wooss_origin_city ) ); ?>" readonly> 332 </span> 333 334 335 <br /> 336 <br /> 337 <span style="display:none;"><strong><?php esc_html_e( 'Destination Details : ', 'wooss' ); ?></strong> 338 <i>This represents your customer details</i> 339 <br /> 340 <strong><label for="wooss_destination_name"><?php esc_html_e( 'Name : ', 'wooss' ); ?></label></strong> 341 <input type="text" name="wooss_destination_name" id="wooss_destination_name" class="wooss-text" value="<?php esc_html_e( $destination_name ); ?>" readonly> 342   343 <label><label for="wooss_destination_phone"><?php esc_html_e( 'Phone : ', 'wooss' ); ?></label></label> 344 <input type="text" name="wooss_destination_phone" id="wooss_destination_phone" class="wooss-text" value="<?php esc_html_e( $destination_phone ); ?>" readonly> 345 <br />  346 347 <br /><strong><label for="wooss_destination_email"><?php esc_html_e( 'Email : ', 'wooss' ); ?></label></strong> 348 <input type="text" name="wooss_destination_email" id="wooss_destination_email" class="wooss-text" value="<?php esc_html_e( $destination_email ); ?>" readonly> 349   350 <strong><label for="wooss_destination_street"><?php esc_html_e( 'Street : ', 'wooss' ); ?></label></strong> 351 <input type="text" name="wooss_destination_street" id="wooss_destination_street" class="wooss-text" value="<?php esc_html_e( $destination_street ); ?>" readonly> 352 <br />  353 <br /><strong><label for="wooss_destination_country"><?php esc_html_e( 'Country : ', 'wooss' ); ?></label></strong> 354 <input type="text" name="wooss_destination_country" id="wooss_destination_country" class="wooss-text" value="<?php esc_html_e( $destination_country ); ?>" readonly> 355   356 <strong><label for="wooss_destination_state"><?php esc_html_e( 'State : ', 'wooss' ); ?></label></strong> 357 <input type="text" name="wooss_destination_state" id="wooss_destination_state" class="wooss-text" value="<?php esc_html_e( $destination_state ); ?>" readonly> 358 <br />  359 <br /><strong><label for="wooss_destination_city"><?php esc_html_e( 'City : ', 'wooss' ); ?></label></strong> 360 <input type="text" name="wooss_destination_city" id="wooss_destination_city" class="wooss-text" value="<?php esc_html_e( $destination_city ); ?>" readonly> 361 </span> 362 363 <?php 364 $product_content = ''; 365 foreach ( $items_lists as $lists_id => $list_data ) { 366 $product_name = $list_data->name; 367 $product_quantity = $list_data->quantity; 368 $product_value = $list_data->value; 369 $product_amount = $list_data->amount_to_receive; 370 $product_package_size_code = $list_data->package_size_code; 371 $product_item_type_code = $list_data->item_type_code; 372 $product_weights = $list_data->weight; 373 $product_content .= '{"name" : "' . $product_name . '", "quantity" :"' . $product_quantity . '", "value" :"' . $product_value . '", "amount_to_receive" :"' . $product_amount . '", "package_size_code":"' . $product_package_size_code . '", "item_type":"' . $product_item_type_code . '"," weight" :"' . $product_weights . '"}'; 374 } 375 376 // loading the payload 377 378 $payload_data = new stdClass(); 379 $payload_data->origin_name = $wooss_origin_name; 380 // $payload_data->destination_country = $destination_country; 381 $payload_data->destination_country_code = $destination_country; 382 // $payload_data->destination_state_code = ' '; 383 $payload_data->destination_state = $destination_state; 384 $payload_data->destination_city = $destination_city; 385 $payload_data->destination_street = $destination_street; 386 $payload_data->destination_name = $destination_name; 387 $payload_data->destination_phone = $destination_phone; 388 $payload_data->items = $items_lists; 389 $payload_data->weight = (int) $weight * $quantity; 390 $payload_data->amount_to_receive = (int) $fee; 391 $payload_data->origin_country = $wooss_origin_country; 392 $payload_data->origin_state = $wooss_origin_states_selected; 393 394 $payload_data->origin_phone = $wooss_origin_phone; 395 $payload_data->origin_street = $wc_store_address; 396 $payload_data->origin_city = $wooss_origin_city; 397 // $payload_data->deliver_priority_code = 'next_day'; 398 $payload_data->pickup_date = $pickup_date; 399 $payload_data->incoming_option_code = $incoming_option_code; 400 $payload_data->payment_option_code = 'prepaid'; 401 // $payload_data->deliver_type_code = 'last_mile'; 402 403 $payload_data_json = wp_json_encode( $payload_data ); 404 $delivery_args = array( 405 'timeout' => 30, 406 'headers' => array( 407 'Content-Type' => 'application/json', 408 'Authorization' => $auth_header, 409 ), 410 'body' => $payload_data_json, 411 412 ); 413 // print_r($payload_data_json); 414 415 ?> 416 </div> 417 <span> 418 <span> 419 <!--<label?php _e('Items : ', 'wooss'); ?></label> ---> 420 <textarea style="display:none;" cols="50" class="wooss-textarea" id="wooss_items_list" value="<?php esc_html_e( $product_content ); ?>" data-id="<?php echo esc_attr( $order_id ); ?>"><?php trim( esc_html_e( $product_content ) ); ?></textarea> 421 <?php 422 $quote_api_url = $api_call->get_sendbox_api_url( 'delivery_quote' ); 423 $quote_body = $api_call->get_api_response_body( $quote_api_url, $delivery_args, 'POST' ); 424 //var_dump($quote_body); 425 426 $quotes_rates = $quote_body->rates; 427 //var_dump($quotes_rates); 428 // print_r($quote_body); 429 430 $wallet = $quote_body->wallet_balance; 431 432 foreach ( $quotes_rates as $rates_id => $rates_values ) { 433 $rates_names = $rates_values->name; 434 $rates_fee = $rates_values->fee; 435 $rates_id = $rates_values->id; 436 $currency = $rates_values->currency; 437 //print_r($rates_values); 438 } 439 440 ?> 441 <span id="wooss_shipments_data"> 442 <div style="text-align : left; display: flex; flex-direction: row; justify-content: space-between; align-items: center;"> 443 444 <b> 445 <?php 446 esc_attr_e( 'WALLET BALANCE' ); 447 ?> 448 </b> 449 450 <b> 451 <?php 452 esc_attr_e( $currency . $wallet ); 453 454 ?> 455 </b> 456 457 </div> 458 459 <select id="wooss_selected_courier" > 460 <option value=""> <?php esc_attr_e( 'Select a courier... ' ); ?> </option> 461 <?php 462 463 foreach ( $quotes_rates as $rates_id => $rates_values ) { 464 $rates_names = $rates_values->name; 465 $rates_fee = $rates_values->fee; 466 $rates_id = $rates_values->courier_id; 467 $currency = $rates_values->currency; 468 469 ?> 470 <option data-courier-price="<?php esc_attr_e( $rates_fee, 'wooss' ); ?> " value="<?php esc_attr_e( $rates_id, 'wooss' ); ?>" id="<?php _e( $rates_id, 'wooss' ); ?>"><?php esc_attr_e( $rates_names ); ?></option> 471 472 <?php 473 } 474 ?> 475 476 </select> 477 478 <?php 479 480 // for the countries 481 482 unset( $args['headers']['Authorization'] ); 483 $countries_api_url = add_query_arg( 'page_by', '{"per_page":264}', 'https://api.sendbox.co/auth/countries' ); 484 $countries_data_obj = wp_remote_get( $countries_api_url, $args ); 485 486 487 // https://api.sendbox.co/auth/states?page_by={"per_page":10000}&country_code=NG 488 $countries_body = json_decode( wp_remote_retrieve_body( $countries_data_obj ) ); 489 490 ?> 491 492 <label><h4><b>ORIGIN NAME</b></h4></label> 493 <input class ="custom_input" required type="text" name="origin_name" placeholder="<?php esc_attr_e("Please Enter Origin Name")?>" id="origin_name" value=" " /> 494 495 <label><h4><b>ORIGIN PHONE</b></h4></label> 496 <input class ="custom_input" required type="tel" name="origin_phone" placeholder="<?php esc_attr_e("Please Enter Origin Phone")?>" id="origin_phone" value=" " /> 497 498 499 500 <label><h4><b>ORIGIN COUNTRY</b></h4></label> 501 <select class ="custom_input" id = "wooss_origin_country"> 502 <option data-country-code="default" value=""> 503 <?php _e( 'Please select origin country' ); ?> 504 </option> 505 506 <?php 507 foreach ( $countries_body as $key => $value ) { 508 if ( is_array( $value ) ) { 509 sort( $value ); 510 foreach ( $value as $ship_key => $ship_value ) { 511 echo "<option data-country-code='" . $ship_value->code . "' value='" . $ship_value->name . "'>" . $ship_value->name . ' </option>'; 512 513 } 514 } 515 } 516 ?> 517 </select> 518 519 <?php 520 521 //$country_code_default = 'NG'; 522 523 $states_api_url = add_query_arg( 524 array( 525 'page_by' => '{"per_page":10000}', 526 'filter_by' => '{"country_code":"' . $country_code_default . '"}', 527 ), 528 'https://api.sendbox.co/auth/states' 529 ); 530 $states_data_obj = wp_remote_get( $states_api_url, $args ); 531 532 $states_body = json_decode( wp_remote_retrieve_body( $states_data_obj ) ); 533 534 ?> 535 536 <label><h4><b>ORIGIN STATE</b></h4></label> 537 <select class ="custom_input" id = "wooss_origin_states_selected"> 538 <option data-state-code="default" value = ""> 539 <?php _e( 'Please select origin state' ); ?> 540 </option> 541 542 <?php 543 foreach ( $states_body as $states_key => $states_values ) { 544 if ( is_array( $states_values ) ) { 545 sort( $states_values ); 546 547 foreach ( $states_values as $ship_state_key => $ship_state_value ) { 548 549 if ( ! empty( $ship_state_value ) ) { 550 echo "<option data-states-code='" . $ship_value->code . "' value=" . $ship_state_value->name . '>' . $ship_state_value->name . ' </option>'; 551 } 552 } 553 } 554 } 555 ?> 556 </select> 557 558 559 560 561 <label><h4><b>ORIGIN STREET</b></h4></label> 562 <input class ="custom_input" required type="text" name="origin_street" placeholder="<?php esc_attr_e("Please Enter Origin Street")?>" id="origin_street" value=" " /> 563 564 <label><h4><b>ORIGIN CITY</b></h4></label> 565 <input class ="custom_input" required type="text" name="origin_city" placeholder="<?php esc_html_e("Please Enter Origin City")?>" id="origin_city" value=" " /> 566 567 <?php //end of origin street?> 568 <label><h4><b>DESTINATION COUNTRY</b></h4></label> 569 <select id = "wooss_destination_country"> 570 <option data-country-code="default" value=""> 571 <?php _e( 'Please select destination country' ); ?> 572 </option> 573 574 <?php 575 foreach ( $countries_body as $key => $value ) { 576 if ( is_array( $value ) ) { 577 sort( $value ); 578 foreach ( $value as $ship_key => $ship_value ) { 579 echo "<option data-country-code='" . $ship_value->code . "' value='" . $ship_value->name . "'>" . $ship_value->name . ' </option>'; 580 581 } 582 } 583 } 584 ?> 585 </select> 586 587 <?php // end of countries ?> 588 589 <?php 590 591 //$country_code_default = 'NG'; 592 593 $states_api_url = add_query_arg( 594 array( 595 'page_by' => '{"per_page":10000}', 596 'filter_by' => '{"country_code":"' . $country_code_default . '"}', 597 ), 598 'https://api.sendbox.co/auth/states' 599 ); 600 $states_data_obj = wp_remote_get( $states_api_url, $args ); 601 602 $states_body = json_decode( wp_remote_retrieve_body( $states_data_obj ) ); 603 604 ?> 605 <label><h4><b>DESTINATION STATE</b></h4></label> 606 <select id = "wooss_destination_state" > 607 <option data-state-code="default" value = ""> 608 <?php _e( 'Please select destination state' ); ?> 609 </option> 610 611 <?php 612 foreach ( $states_body as $states_key => $states_values ) { 613 if ( is_array( $states_values ) ) { 614 sort( $states_values ); 615 616 foreach ( $states_values as $ship_state_key => $ship_state_value ) { 617 618 if ( ! empty( $ship_state_value ) ) { 619 echo "<option data-states-code='" . $ship_value->code . "' value=" . $ship_state_value->name . '>' . $ship_state_value->name . ' </option>'; 620 } 621 } 622 } 623 } 624 ?> 625 </select> 626 627 628 <?php 629 630 //$country_code_default = 'NG'; 631 if ( $sendbox_data[ 'wooss_selected_country_code_used' ] ) { 632 $country_code_default = $sendbox_data[ 'wooss_selected_country_code_used' ]; 633 } 634 635 $city_api_url = add_query_arg( 636 array( 637 'page_by' => '{"per_page":10000}', 638 'filter_by' => '{"country_code":"' . $country_code_default . '"}', 639 ), 640 'https://api.sendbox.co/auth/cities' 641 ); 642 $city_data_obj = wp_remote_get( $city_api_url, $args ); 643 644 $city_body = json_decode( wp_remote_retrieve_body( $city_data_obj ) ); 645 646 ?> 647 <!-- <input id= "wooss_destination_city_name" type="text" placeholder="Enter Destination City" value="<?php //esc_html_e( $destination_city ); ?>"> --> 648 <label><h4><b>DESTINATION STREET</b></h4></label> 649 <input placeholder="Please Enter Destination Street" class ="custom_input" required type="text" name="destination_street" id="destination_street" value=" " /> 650 651 <label><h4><b>DESTINATION CITY</b></h4></label> 652 <input class ="custom_input" placeholder="Please Enter Destination City" required type="text" name="destination_city" id="destination_city" value=" " /> 653 654 655 <?php 656 657 $postal_code = $_order->get_billing_postcode(); 658 659 if ( ! empty( $postal_code ) ) { 660 661 echo "<input id= 'wooss_postal_code' type='text' value='" . $postal_code . "' placeholder='Enter Postal Code'>"; 662 } 663 664 ?> 665 666 <br /> 667 <div style="text-align : left; display: flex; flex-direction: row; justify-content: space-between; align-items: center;"> 668 669 <b id="dabs"> 670 <?php 671 /* esc_attr_e( 'Fee: 0.0' ); */ 672 ?> 673 </b> 674 675 <button id="wooss_request_shipment" class="button-primary"><?php esc_html_e( 'Request Shipment' ); ?></button> 676 </div> 677 </span> 678 </span> 679 <?php 680 } 681 } 682 } 527 <div style="text-align:center;"> 528 <button id="wooss_request_shipment" class="button-primary"><?php esc_html_e( 'Request Shipment', 'wooss' ); ?></button> 529 </div> 530 </div> 531 </div> 532 533 <?php 534 echo ob_get_clean(); 535 } 536 683 537 684 538 /** … … 694 548 $_order = new WC_Order( $order_id ); 695 549 $customer_products = $_order->get_items(); 696 $items_lists = array();697 698 $fee = 0;699 $quantity = 0;700 701 foreach ( $customer_products as $products_data ) {702 $product_data = $products_data->get_data();703 $product_id = $product_data['product_id'];704 $_product = wc_get_product( $product_id );705 $items_data = new stdClass();706 $items_data->name = $product_data['name'];707 $items_data->quantity = $product_data['quantity'];708 $items_data->value = $_product->get_price();709 $items_data->amount_to_receive = $_product->get_price();710 $items_data->package_size_code = 'medium';711 $items_data->item_type_code = strip_tags( wc_get_product_category_list( $product_id ) );712 713 $product_weight = $_product->get_weight();714 if ( null != $product_weight ) {715 $weight = $product_weight;716 } else {717 $weight = 0;718 }719 720 $fee += round( $_product->get_price() );721 $quantity += $product_data['quantity'];722 $items_data->weight = $weight * $quantity;723 array_push( $items_lists, $items_data );724 }725 726 $courier_selected = sanitize_text_field( $data['wooss_selected_courier'] );727 728 $destination_name = sanitize_text_field( $data['wooss_destination_name'] );729 $destination_phone = sanitize_text_field( $data['wooss_destination_phone'] );730 $destination_email = sanitize_text_field( $data['wooss_destination_email'] );731 $destination_city = sanitize_text_field( $data['wooss_destination_city'] );732 $destination_country = sanitize_text_field( $data['wooss_destination_country'] );733 $destination_state = sanitize_text_field( $data['wooss_destination_state'] );734 $destination_street = sanitize_text_field( $data['wooss_destination_street'] );735 736 $origin_name = sanitize_text_field( $data['wooss_origin_name'] );737 $origin_phone = sanitize_text_field( $data['wooss_origin_phone'] );738 $origin_email = sanitize_text_field( $data['wooss_origin_email'] );739 $origin_city = sanitize_text_field( $data['wooss_origin_city'] );740 $origin_state = sanitize_text_field( $data['wooss_origin_state'] );741 $origin_street = sanitize_text_field( $data['wooss_origin_street'] );742 $origin_country = sanitize_text_field( $data['wooss_origin_country'] );743 744 $destination_post_code = sanitize_text_field( $data['wooss_postal_code'] );745 550 746 551 $webhook_url = get_site_url() . '/wp-json/wooss/v2/shipping'; 747 552 748 553 $payload_data = new stdClass(); 749 750 // $payload_data->selected_courier_id = $courier_selected; 751 752 $payload_data->destination_name = $destination_name; 753 $payload_data->destination_phone = $destination_phone; 754 $payload_data->destination_email = $destination_email; 755 $payload_data->destination_city = $destination_city; 756 $payload_data->destination_country = $destination_country; 757 $payload_data->destination_state = $destination_state; 758 $payload_data->destination_street = $destination_street; 759 $payload_data->weight = $product_weight; 760 $payload_data->origin_name = $origin_name; 761 $payload_data->origin_phone = $origin_phone; 762 $payload_data->origin_email = $origin_email; 763 $payload_data->origin_city = $origin_city; 764 $payload_data->origin_state = $origin_state; 765 $payload_data->origin_street = $origin_street; 766 $payload_data->origin_country = $origin_country; 767 $payload_data->items = $items_lists; 768 $payload_data->reference_code = trim( str_replace( '#', '', $order_id ) ); 769 $payload_data->amount_to_receive = $_order->get_shipping_total(); 770 $payload_data->delivery_callback = $webhook_url; 771 $payload_data->destination_post_code = $destination_post_code; 554 $payload_data->origin_name = sanitize_text_field($data["origin_name"]); 555 $payload_data->destination_country_code = sanitize_text_field($data["destination_country_code"]); 556 $payload_data->destination_state = sanitize_text_field($data["destination_state"]); 557 $payload_data->destination_city = sanitize_text_field($data["destination_city"]); 558 $payload_data->destination_street = sanitize_text_field($data["destination_street"]); 559 $payload_data->destination_name = sanitize_text_field($data["destination_name"]); 560 $payload_data->destination_phone = sanitize_text_field($data["destination_phone"]); 561 $payload_data->items = $data["items"]; 562 $payload_data->weight = sanitize_text_field($data["weight"]); 563 $payload_data->amount_to_receive = sanitize_text_field($data["amount_to_receive"]); 564 $payload_data->origin_country = sanitize_text_field($data["origin_country"]); 565 $payload_data->origin_state = sanitize_text_field($data["origin_state"]); 566 $payload_data->origin_phone = sanitize_text_field($data["origin_phone"]); 567 $payload_data->origin_street = sanitize_text_field($data["origin_street"]); 568 $payload_data->origin_city = sanitize_text_field($data["origin_city"]); 569 $payload_data->pickup_date = sanitize_text_field($data["pickup_date"]); 570 $payload_data->incoming_option_code = sanitize_text_field($data["incoming_option_code"]); 571 $payload_data->payment_option_code = sanitize_text_field($data["payment_option_code"]); 572 573 $payload_data->delivery_callback = $webhook_url; 574 772 575 773 576 $date = new DateTime(); … … 775 578 $pickup_date = $date->format( 'c' ); 776 579 777 $payload_data->deliver_priority_code = 'next_day';778 580 $payload_data->pickup_date = $pickup_date; 779 581 $payload_data->channel_code = 'api'; 780 $payload_data->rate_code = 'standard';781 582 782 583 $api_call = new Wooss_Sendbox_Shipping_API(); … … 784 585 $auth_header = Wooss_Sendbox_Shipping_API::checkAuth(); 785 586 786 $payload_data_json = wp_json_encode( $ payload_data );587 $payload_data_json = wp_json_encode( $data ); 787 588 788 589 $shipments_args = array( … … 831 632 'methods' => 'POST', 832 633 'callback' => array( $this, 'post_data' ), 634 'permission_callback' => '__return_true', 833 635 ) 834 636 ); -
sendbox-shipping/trunk/admin/js/wooss-admin.js
r2776138 r3255662 35 35 36 36 $(document).ready(function () { 37 $('select#wooss_destination_country').select2(); 38 $('select#wooss_destination_state').select2(); 39 40 //start of new kini i am trying for origin 41 $('select#wooss_origin_country').select2(); 42 $('select#wooss_origin_states_selected').select2(); 43 44 37 var payload = JSON.parse(document.getElementById('wooss_payload_data').value); 45 38 var select_choosed = $('select[name="wc_order_action"]').val(); 46 39 $('select[name="wc_order_action"]').change(function () { … … 56 49 }); 57 50 58 var request_shipment_btn = $("button#wooss_request_shipment");59 request_shipment_btn.on("submit click", function (e) {60 e.preventDefault();61 //var wooss_origin_name = $("input[name='wooss_origin_name']").val();62 //var wooss_origin_phone = $("input[name='wooss_origin_phone']").val();51 // Listen for changes on the courier selection dropdown 52 $('#wooss_selected_courier').on('change', function() { 53 var selectedOption = $(this).find('option:selected'); 54 var newFee = selectedOption.data('courier-price'); // get the fee value from the data attribute 55 var courierId = selectedOption.val(); // get the courier id 63 56 64 var wooss_origin_name = $("input#origin_name").val(); 65 $('input#origin_name').on('input',function(e){ 66 wooss_origin_name = $(this).val(); 67 }); 57 // Update the fee in the element with id "dabs" 58 $('#dabs').text(newFee); 59 document.getElementById("dabs").style.color = "#ed2f59"; 68 60 69 var wooss_origin_phone = $("input#origin_phone").val(); 70 $('input#origin_phone').on('input',function(e){ 71 wooss_origin_phone = $(this).val(); 72 }); 73 61 // Get values from origin fields; update payload if they have a non-empty value 62 var originName = $('#wooss_origin_name').val(); 63 var originPhone = $('#wooss_origin_phone').val(); 64 var originEmail = $('#wooss_origin_email').val() || ''; // if there is an origin email field 65 var originStreet = $('#wooss_origin_street').val(); 66 var originState = $('#wooss_origin_state').val(); 67 // For a disabled select, get the text of the selected option as the country value 68 var originCountry = $('#wooss_origin_country').find('option:selected').text(); 74 69 75 var wooss_origin_email = $("input[name='wooss_origin_email']").val(); 76 //var wooss_origin_country = $("input[name='wooss_origin_country']").val(); 77 //var wooss_origin_street = $("input[name='wooss_origin_street']").val(); 78 //var wooss_origin_state = $("input[name='wooss_origin_state']").val(); 79 //var wooss_origin_city = $("input[name='wooss_origin_city']").val(); 70 if (originName !== '') { 71 payload.origin_name = originName; 72 } 73 if (originPhone !== '') { 74 payload.origin_phone = originPhone; 75 } 76 if (originEmail !== '') { 77 payload.origin_email = originEmail; 78 } 79 if (originStreet !== '') { 80 payload.origin_street = originStreet; 81 } 82 if (originState !== '') { 83 payload.origin_state = originState; 84 } 85 if (originCountry !== '') { 86 payload.origin_country = originCountry 80 87 81 var wooss_destination_name = $( 82 "input[name = 'wooss_destination_name']" 83 ).val(); 88 } 84 89 85 var wooss_destination_phone = $( 86 "input[name = 'wooss_destination_phone']" 87 ).val(); 88 var wooss_destination_email = $( 89 "input[name = 'wooss_destination_email']" 90 ).val(); 91 /* var wooss_destination_street = $( 92 "input[name = 'wooss_destination_street']" 93 ).val(); */ 94 /* var wooss_destination_country = $( 95 "input[name = 'wooss_destination_country']" 96 ).val(); 97 var wooss_destination_state = $( 98 "input[name = 'wooss_destination_state']" 99 ).val();*/ 90 // Add the selected courier id as service_code to the payload 91 if (courierId !== '') { 92 payload.service_code = courierId; 93 } 100 94 101 //var wooss_destination_city = $("input[name = 'wooss_destination_city']").val(); 102 var wooss_postal_code = $( 103 "input#wooss_postal_code" 104 ).val(); 95 if (!payload.destination_phone){ 96 payload.destination_phone = payload.origin_phone 97 } 105 98 106 var wooss_selected_courier = $("select#wooss_selected_courier").val(); 107 $("select#wooss_selected_courier").change(function () { 108 wooss_selected_courier = $(this).val(); 109 //console.log(wooss_selected_courier, "hahh"); 110 }); 99 }); 100 var request_shipment_btn = $("button#wooss_request_shipment"); 101 request_shipment_btn.on("submit click", function (e) { 102 e.preventDefault(); 111 103 112 var wooss_destination_country = $("select#wooss_destination_country").val(); 113 $("select#wooss_destination_country").change(function () { 114 wooss_destination_country = $(this).val(); 104 var wooss_order_id = $("textarea#wooss_items_list").data("id"); 115 105 116 }) 106 $.blockUI({message: 'Requesting shipment...'}); 107 payload.reference_code = wooss_order_id 108 payload.wooss_order_id = wooss_order_id 109 // Assuming payload is your payload object 110 Object.keys(payload).forEach(function(key) { 111 if (typeof payload[key] === 'string') { 112 payload[key] = payload[key].trim(); 113 } 114 }); 117 115 118 //start of new origin kini i am trying 119 var wooss_origin_country = $("select#wooss_origin_country").val(); 120 $("select#wooss_origin_country").change(function () { 121 wooss_origin_country = $(this).val(); 122 }) 116 $.post( 117 wooss_ajax_object.wooss_ajax_url, 118 { 119 action: "request_shipments", 120 data: payload, 121 security: wooss_ajax_object.wooss_ajax_security 122 }, 123 function (response) { 123 124 124 var wooss_origin_state = $("select#wooss_origin_states_selected").val(); 125 $("select#wooss_origin_states_selected").change(function () { 126 wooss_origin_state = $(this).val(); 125 $.unblockUI(); 126 if (response == 0) { 127 alert("An error occured"); 128 } else if (response == 1) { 129 alert("Shipment Successful"); 130 window.location.reload(); 131 } else if (response == 2 || response == 3) { 127 132 128 }) 129 130 var wooss_origin_street = $("input#origin_street").val(); 131 $('input#origin_street').on('input',function(e){ 132 wooss_origin_street = $(this).val(); 133 }); 134 135 var wooss_origin_city = $("input#origin_city").val(); 136 $('input#origin_city').on('input',function(e){ 137 wooss_origin_city = $(this).val(); 138 }); 139 140 var wooss_destination_city = $("input#destination_city").val(); 141 $('input#destination_city').on('input',function(e){ 142 wooss_destination_city = $(this).val(); 143 }); 144 145 var wooss_destination_street = $("input#destination_street").val(); 146 $('input#destination_street').on('input',function(e){ 147 wooss_destination_street = $(this).val(); 148 }); 149 150 var wooss_destination_state = $("select#wooss_destination_state").val(); 151 $("select#wooss_destination_state").change(function () { 152 wooss_destination_state = $(this).val() 153 }) 154 155 156 var wooss_country_destination_name = $("input#wooss_destination_city_name").val(); 157 158 159 var wooss_order_id = $("textarea#wooss_items_list").data("id"); 160 161 $.blockUI({message: 'Requesting shipment...'}); 162 163 164 var data = { 165 wooss_origin_name: wooss_origin_name, 166 wooss_origin_phone: wooss_origin_phone, 167 wooss_origin_email: wooss_origin_email, 168 wooss_origin_country: wooss_origin_country, 169 wooss_origin_state: wooss_origin_state, 170 wooss_origin_city: wooss_origin_city, 171 wooss_origin_street: wooss_origin_street, 172 173 wooss_destination_name: wooss_destination_name, 174 wooss_destination_phone: wooss_destination_phone, 175 wooss_destination_email: wooss_destination_email, 176 wooss_destination_country: wooss_destination_country, 177 wooss_destination_state: wooss_destination_state, 178 wooss_destination_street: wooss_destination_street, 179 wooss_destination_city: wooss_destination_city, 180 wooss_selected_courier: wooss_selected_courier, 181 wooss_postal_code: wooss_postal_code, 182 183 184 wooss_order_id: wooss_order_id 185 }; 186 //console.log(wooss_destination_state); 187 188 $.post( 189 wooss_ajax_object.wooss_ajax_url, 190 { 191 action: "request_shipments", 192 data: data, 193 security: wooss_ajax_object.wooss_ajax_security 194 }, 195 function (response) { 196 197 $.unblockUI(); 198 if (response == 0) { 199 alert("An error occured"); 200 } else if (response == 1) { 201 alert("Shipment Successful"); 202 window.location.reload(); 203 } else if (response == 2 || response == 3) { 204 alert( 205 "insufficient funds login to your sendbox account and top up your wallet" 206 ); 207 } 208 } 209 ); 210 }); 211 212 $("select#wooss_selected_courier").change(function (event) { 213 let price = 214 event.target.options[event.target.selectedIndex].dataset.courierPrice; 215 document.getElementById("dabs").innerText = "Fee: " + price; 216 document.getElementById("dabs").style.color = "#ed2f59"; 217 //console.log(wooss_selected_courier, "hahh"); 218 }); 219 /***function to display rates */ 220 221 222 /***Function to get country code**/ 223 var wooss_selected_country, wooss_selected_country_code; 224 $("select#wooss_destination_country").on('change ', function () { 225 var wooss_selected_option = jQuery(this).children("option:selected"); 226 wooss_selected_country = wooss_selected_option.val(); 227 wooss_selected_country_code = wooss_selected_option.data("countryCode"); 228 $.blockUI(); 229 230 $.post(wooss_ajax_object.wooss_ajax_url, { 231 action: "request_states", 232 data: wooss_selected_country_code, 233 security: wooss_ajax_object.wooss_ajax_security 234 }, 235 function (response) { 236 if (response) { 237 $("select#wooss_destination_state option:gt(0)").remove(); 238 $('select#wooss_destination_state').append(response); 239 $.unblockUI(); 240 } 241 }); 242 243 244 }); 245 246 //doing for origin state 247 $("select#wooss_origin_country").on('change ', function () { 248 var wooss_selected_option = jQuery(this).children("option:selected"); 249 wooss_selected_country = wooss_selected_option.val(); 250 wooss_selected_country_code = wooss_selected_option.data("countryCode"); 251 $.blockUI(); 252 253 $.post(wooss_ajax_object.wooss_ajax_url, { 254 action: "request_states", 255 data: wooss_selected_country_code, 256 security: wooss_ajax_object.wooss_ajax_security 257 }, 258 function (response) { 259 if (response) { 260 $("select#wooss_origin_states_selected option:gt(0)").remove(); 261 $('select#wooss_origin_states_selected').append(response); 262 $.unblockUI(); 263 } 264 }); 265 266 267 }); 133 alert( 134 "insufficient funds login to your sendbox account and top up your wallet" 135 ); 136 } 137 } 138 ); 139 }); 268 140 }); 269 141 })(jQuery); -
sendbox-shipping/trunk/includes/class-wooss-shipping-method.php
r3255617 r3255662 80 80 */ 81 81 public function calculate_shipping( $package = array() ) { 82 if ( is_cart() || is_checkout() ) { 83 $api_call = new Wooss_Sendbox_Shipping_API(); 84 $quotes_fee = 0; 85 $fee = 0; 86 $quantity = 0; 87 $items_lists = array(); 88 $sendbox_data = get_option( 'sendbox_data' ); 89 $wooss_extra_fees = esc_attr( $sendbox_data[ 'wooss_extra_fees' ] ); 90 foreach ( $package['contents'] as $item_id => $values ) { 91 if ( ! empty( $values['data']->get_weight() ) ) { 92 $weight = $values['data']->get_weight(); 93 } else { 94 $weight = 0; 82 // Collect package data and build items list 83 $fee = 0; 84 $quantity = 0; 85 $items_lists = array(); 86 foreach ( $package['contents'] as $item_id => $values ) { 87 $weight = ! empty( $values['data']->get_weight() ) ? $values['data']->get_weight() : 0; 88 $fee += round( $values['line_total'] ); 89 $quantity += $values['quantity']; 90 91 $output = new stdClass(); 92 $output->name = $values['data']->get_name(); 93 $output->weight = (int) $weight; 94 $output->package_size_code = 'medium'; 95 $output->quantity = $values['quantity']; 96 $output->value = round( $values['line_total'] ); 97 $output->amount_to_receive = round( $values['line_total'] ); 98 $output->item_type = $values['data']->get_categories(); 99 $items_lists[] = $output; 100 } 101 102 // Retrieve sendbox settings and API authentication 103 $sendbox_data = get_option( 'sendbox_data' ); 104 $wooss_extra_fees = isset( $sendbox_data['wooss_extra_fees'] ) ? esc_attr( $sendbox_data['wooss_extra_fees'] ) : 0; 105 $api_call = new Wooss_Sendbox_Shipping_API(); 106 $auth_header = Wooss_Sendbox_Shipping_API::checkAuth(); 107 if ( ! $auth_header ) { 108 wc_add_notice( __( 'Unable to get shipping fees at this time.', 'wooss' ), 'error' ); 109 return; 110 } 111 112 // Build payload data (simplified; adjust as needed) 113 $origin_country = $sendbox_data['wooss_country']; 114 $origin_state = $sendbox_data['wooss_state_name']; 115 $origin_street = $sendbox_data['wooss_street']; 116 $origin_city = $sendbox_data['wooss_city']; 117 $incoming_option_code = $sendbox_data['wooss_pickup_type']; 118 119 // Set destination details from package 120 $destination_country = wooss_get_countries( $package, 'country' ); 121 $destination_state = wooss_get_countries( $package, 'state' ); 122 $destination_city = ! empty( $package['destination']['city'] ) ? $package['destination']['city'] : 'Unknown City'; 123 $destination_street = ! empty( $package['destination']['address'] ) ? $package['destination']['address'] : __( 'Customer street', 'wooss' ); 124 if ( empty( $destination_state ) ) { 125 $destination_state = 'London'; 126 } 127 // Remove any commas and extra data if needed 128 if ( strpos( $destination_state, ',' ) !== false ) { 129 $stateParts = explode( ',', $destination_state ); 130 $destination_state = trim( end( $stateParts ) ); 131 } 132 if ( strpos( $destination_city, ',' ) !== false ) { 133 $cityParts = explode( ',', $destination_city ); 134 $destination_city = trim( $cityParts[0] ); 135 } 136 137 // Calculate total weight (if needed adjust the logic) 138 $total_weight = $quantity * $weight; 139 140 // Pickup date: set as tomorrow 141 $date = new DateTime(); 142 $date->modify( '+1 day' ); 143 $pickup_date = $date->format( DateTime::ATOM ); 144 145 // Set other payload details 146 $currency = get_option( 'woocommerce_currency' ); 147 $service_code = 'standard'; // Or adjust as necessary 148 149 $payload_array_data = array( 150 'destination_name' => __( 'Customer X', 'wooss' ), 151 'destination_phone' => __( '00000000', 'wooss' ), 152 'destination_country' => $destination_country, 153 'destination_state' => $destination_state, 154 'destination_street' => $destination_street, 155 'destination_city' => $destination_city, 156 'items_list' => $items_lists, 157 'weight' => $total_weight, 158 'amount_to_receive' => (int) $fee, 159 'origin_country' => $origin_country, 160 'origin_name' => '', // You can set these from API profile if available. 161 'origin_street' => $origin_street, 162 'origin_state' => $origin_state, 163 'origin_phone' => '', // Set as needed. 164 'origin_city' => $origin_city, 165 'deliver_priority_code' => 'next_day', 166 'deliver_type_code' => 'last_mile', 167 'payment_option_code' => 'prepaid', 168 'incoming_option_code' => $incoming_option_code, 169 'pickup_date' => $pickup_date, 170 'currency' => $currency, 171 'service_code' => $service_code, 172 ); 173 174 // Make the API call only once 175 $delivery_quotes_details = wooss_calculate_shipping( $api_call, $payload_array_data, $auth_header ); 176 if ( ! is_object( $delivery_quotes_details ) ) { 177 wc_add_notice( __( 'Unable to calculate shipping rates.', 'wooss' ), 'error' ); 178 return; 179 } 180 181 // Check for multiple rates 182 if ( isset( $delivery_quotes_details->rates ) && is_array( $delivery_quotes_details->rates ) && ! empty( $delivery_quotes_details->rates ) ) { 183 foreach ( $delivery_quotes_details->rates as $index => $rate ) { 184 // Calculate final fee (ensure fee and extra fees are numeric) 185 $quoted_fee = floatval( $rate->fee ) + floatval( $wooss_extra_fees ); 186 187 // Build label with optional service details 188 $label = $this->title; 189 if ( ! empty( $rate->service_code ) ) { 190 $label .= ' - ' . $rate->service_code; 191 } elseif ( ! empty( $rate->description ) ) { 192 $label .= ' - ' . $rate->description; 95 193 } 96 $fee += round( $values['line_total'] ); 97 $quantity += $values['quantity']; 98 99 $outputs = new stdClass(); 100 $outputs->name = $values['data']->get_name(); 101 $outputs->weight = (int) $weight; 102 $outputs->package_size_code = 'medium'; 103 $outputs->quantity = $values['quantity']; 104 $outputs->value = round( $values['line_total'] ); 105 $outputs->amount_to_receive = round( $values['line_total'] ); 106 $outputs->item_type = $values['data']->get_categories(); 107 108 array_push( $items_lists, $outputs ); 194 195 // Create a unique rate ID (append index or service code) 196 $rate_id = $this->id . '_' . $index; 197 $new_rate = array( 198 'id' => $rate_id, 199 'label' => $label, 200 'cost' => $quoted_fee, 201 'package' => $package, 202 ); 203 $this->add_rate( $new_rate ); 109 204 } 110 111 112 $auth_header = Wooss_Sendbox_Shipping_API::checkAuth(); 113 114 if ( ! $auth_header ) { 115 wc_add_notice( sprintf( '<strong>Unable to get shipping fees at this time.</strong>' ), 'error' ); 116 } 117 118 //MAKING CHANGES HERE 119 //$origin_country = 'Nigeria';// get_option('wooss_country'); 120 $origin_country = $sendbox_data['wooss_country']; 121 $origin_state = $sendbox_data['wooss_state_name']; 122 123 $origin_street = $sendbox_data['wooss_street']; 124 125 $origin_city = $sendbox_data['wooss_city']; 126 127 $incoming_option_code = $sendbox_data['wooss_pickup_type']; 128 129 $profile_url = $api_call->get_sendbox_api_url( 'profile' ); 130 $profile_args = array( 131 'timeout' => 30, 132 'headers' => array( 133 'Content-Type' => 'application/json', 134 'Authorization' => $auth_header, 135 ), 205 } elseif ( isset( $delivery_quotes_details->rate ) && is_object( $delivery_quotes_details->rate ) ) { 206 // Fallback to single rate response 207 $quoted_fee = floatval( $delivery_quotes_details->rate->fee ) + floatval( $wooss_extra_fees ); 208 $new_rate = array( 209 'id' => $this->id, 210 'label' => $this->title, 211 'cost' => $quoted_fee, 212 'package' => $package, 136 213 ); 137 $response_code_from_profile_api = $api_call->get_api_response_code( $profile_url, $profile_args, 'GET' ); 138 $response_body_from_profile_api = $api_call->get_api_response_body( $profile_url, $profile_args, 'GET' ); 139 if ( 200 === $response_code_from_profile_api ) { 140 $origin_name = $response_body_from_profile_api->name; 141 $origin_phone = $response_body_from_profile_api->phone; 142 $origin_email = $response_body_from_profile_api->email; 143 } 144 $date = new DateTime(); 145 $date->modify( '+1 day' ); 146 $pickup_date = $date->format( DateTime::ATOM ); 147 148 $destination_state_code = $package['destination']['country']; 149 $destination_city = $package['destination']['city']; 150 $destination_street = $package['destination']['address']; 151 if ( empty( $destination_street ) ) { 152 $destination_street = __( 'Customer street' ); 153 } 154 $destination_name = __( 'Customer X', 'wooss' ); 155 $destination_phone = __( '00000000', 'wooss' ); 156 157 $destination_country = wooss_get_countries( $package, 'country' ); 158 $destination_state = wooss_get_countries( $package, 'state' ); 159 $currency = get_option('woocommerce_currency'); 160 161 if ( preg_match( '/\s\(\w+\)/', $destination_country ) == true ) { 162 $destination_country = preg_replace( '/\s\(\w+\)/', '', $destination_country ); 163 } 164 165 if ( preg_match( '/(\s\(\w+\)\s)|(\s\(\w+\))|(\(\w+\)\s)|(\(\w+\))/', $destination_country ) == true ) { 166 $destination_country = preg_replace( '/(\s\(\w+\)\s)|(\s\(\w+\))|(\(\w+\)\s)|(\(\w+\))/', '', $destination_country ); 167 } 168 169 if ( preg_match( '/United States/', $destination_country ) == true ) { 170 $destination_country = 'United States of America'; 171 } 172 173 if ( empty( $destination_state ) ) { 174 // $destination_state = $package['destination']['state']; 175 $destination_state = 'London'; 176 } 177 //remove comma 178 if (strpos($destination_state, ',') !== false) { 179 $stateParts = explode(',', $destination_state); 180 $destination_state = trim(end($stateParts)); 181 } 182 if ( empty( $destination_city ) ) { 183 $destination_city = $package['destination']['city']; 184 } 185 186 if (strpos($destination_city, ',') !== false) { 187 $cityParts = explode(',', $destination_city); 188 $destination_city = trim($cityParts[0]); 189 } 190 191 192 $weight = $quantity * $weight; 193 $service_code = 'standard'; 194 195 $payload_array_data = array( 196 'destination_name' => $destination_name, 197 'destination_phone' => $destination_phone, 198 'destination_country' => $destination_country, 199 'destination_state' => $destination_state, 200 'destination_street' => $destination_street, 201 'destination_city' => $destination_city, 202 'items_list' => $items_lists, 203 'weight' => $weight, 204 'amount_to_receive' => (int) $fee, 205 'origin_country' => $origin_country, 206 'origin_name' => $origin_name, 207 'origin_street' => $origin_street, 208 'origin_state' => $origin_state, 209 'origin_phone' => $origin_phone, 210 'origin_city' => $origin_city, 211 'deliver_priority_code' => 'next_day', 212 'deliver_type_code' => 'last_mile', 213 'payment_option_code' => 'prepaid', 214 'incoming_option_code' => $incoming_option_code, 215 'pickup_date' => $pickup_date, 216 'currency' => $currency, 217 //updating based on the sendbox new change to pass service code September 25th 2024 218 'service_code' => $service_code, 219 220 ); 221 222 $delivery_quotes_details = wooss_calculate_shipping( $api_call, $payload_array_data, $auth_header ); 223 224 // Check if rates is set and is an array 225 if ( isset( $delivery_quotes_details->rates ) && is_array( $delivery_quotes_details->rates ) ) { 226 227 // Loop through each rate option and add it as a shipping rate 228 foreach ( $delivery_quotes_details->rates as $rate ) { 229 // Calculate the total fee with any extra fees 230 $quoted_fee = $rate->fee + $wooss_extra_fees; 231 232 // Build the label. For example, you can append the service code or name if available. 233 // Adjust the label formatting as needed. 234 $label = $this->title; 235 if ( isset( $rate->service_code ) && !empty( $rate->service_code ) ) { 236 $label .= ' - ' . $rate->service_code; 237 } elseif ( isset( $rate->service_name ) && !empty( $rate->service_name ) ) { 238 $label .= ' - ' . $rate->service_name; 239 } 240 241 $new_rate = array( 242 'id' => $this->id, 243 'label' => $label, 244 'cost' => $quoted_fee, 245 'package' => $package, 246 ); 247 248 $this->add_rate( $new_rate ); 249 } 250 251 } else { 252 // Fallback in case the API response doesn't contain a rates array 253 $wooss_rates_type = $sendbox_data['wooss_rates_type']; 254 if ( 'maximum' == $wooss_rates_type && isset( $delivery_quotes_details->rate ) ) { 255 $quotes_fee = $delivery_quotes_details->rate->fee; 256 } elseif ( 'minimum' == $wooss_rates_type && isset( $delivery_quotes_details->rate ) ) { 257 $quotes_fee = $delivery_quotes_details->rate->fee; 258 } 259 $quoted_fee = $quotes_fee + $wooss_extra_fees; 260 261 $new_rate = array( 262 'id' => $this->id, 263 'label' => $this->title, 264 'cost' => $quoted_fee, 265 'package' => $package, 266 ); 267 268 $this->add_rate( $new_rate ); 269 } } 214 $this->add_rate( $new_rate ); 215 } else { 216 wc_add_notice( __( 'No shipping rates available.', 'wooss' ), 'error' ); 217 } 270 218 } 219 271 220 } 272 221 } -
sendbox-shipping/trunk/wooss.php
r3255617 r3255662 16 16 * Plugin URI: # 17 17 * Description: A Sendbox WooCommerce shipping plugin that enables you ship from your store to anywhere in the world. 18 * Version: 5. 118 * Version: 5.2 19 19 * Author: sendbox 20 20 * Author URI: https://sendbox.ng/ … … 35 35 * Rename this for your plugin and update it as you release new versions. 36 36 */ 37 define('WOOSS_VERSION', '5. 1');37 define('WOOSS_VERSION', '5.2'); 38 38 39 39 /**
Note: See TracChangeset
for help on using the changeset viewer.