Changeset 3359066
- Timestamp:
- 09/10/2025 09:49:51 AM (7 months ago)
- Location:
- hippoo-shippo-integration-for-woocommerce/trunk
- Files:
-
- 6 edited
-
hippoo-shippo.php (modified) (2 diffs)
-
inc/helper.php (modified) (1 diff)
-
inc/hooks.php (modified) (2 diffs)
-
inc/shippo-api.php (modified) (1 diff)
-
inc/web-api.php (modified) (5 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
hippoo-shippo-integration-for-woocommerce/trunk/hippoo-shippo.php
r3357076 r3359066 5 5 Description: Hippoo Shippo Integration connects Shippo with the WooCommerce Admin app, allowing you to generate carrier shipping labels directly from your dashboard. Get real-time shipping rates at checkout and support for shipments. Designed by the Hippoo team to streamline your shipping process. 6 6 Short Description: Generate Shippo carrier labels inside WooCommerce Admin with real-time shipping rates at checkout. 7 Version: 1.1. 07 Version: 1.1.1 8 8 Author: Hippoo Team 9 9 License: GPLv2 or later … … 26 26 } 27 27 28 define( 'hippshipp_version', '1.1. 0' );28 define( 'hippshipp_version', '1.1.1' ); 29 29 define( 'hippshipp__FILE__', __FILE__ ); 30 30 define( 'hippshipp_path', plugin_dir_path( __FILE__ ) ); -
hippoo-shippo-integration-for-woocommerce/trunk/inc/helper.php
r3357076 r3359066 249 249 // phpcs:enable 250 250 } 251 252 public static function extract_error_message( $error ) { 253 if ( empty( $error ) ) { 254 return ''; 255 } 256 257 if ( is_string( $error ) ) { 258 return $error; 259 } 260 261 if ( is_array( $error ) || is_object( $error ) ) { 262 $messages = []; 263 $error = (array) $error; 264 265 foreach ( $error as $key => $value ) { 266 if ( is_string( $value ) ) { 267 $messages[] = $value; 268 } elseif ( is_array( $value ) || is_object( $value ) ) { 269 $nested_message = self::extract_error_message( $value ); 270 if ( ! empty( $nested_message ) ) { 271 $prefix = ( $key !== '__all__' && ! is_numeric( $key ) ) ? "$key: " : ''; 272 $messages[] = $prefix . $nested_message; 273 } 274 } 275 } 276 277 if ( empty( $messages ) ) { 278 return ''; 279 } 280 281 return implode( ', ', $messages ); 282 } 283 284 return ''; 285 } 251 286 } -
hippoo-shippo-integration-for-woocommerce/trunk/inc/hooks.php
r3357076 r3359066 146 146 if ( 147 147 ( $hook === 'edit.php' && isset( $_GET['post_type'] ) && sanitize_key( $_GET['post_type'] ) === 'shop_order' ) || 148 ( $hook === 'post.php' && isset( $_GET['post'] ) && get_post_type( sanitize_key( $_GET['post'] ) ) === 'shop_order' ) 148 ( $hook === 'post.php' && isset( $_GET['post'] ) && get_post_type( sanitize_key( $_GET['post'] ) ) === 'shop_order' ) || 149 ( $hook === 'woocommerce_page_wc-orders' && isset( $_GET['page'] ) && sanitize_key( $_GET['page'] ) === 'wc-orders' ) 149 150 ) { 150 151 wp_enqueue_script( 'jquery' ); … … 477 478 } 478 479 479 $uid = get_current_user_id(); 480 $meta = get_user_meta( $uid ); 481 $opt = get_option( 'shippo_options' ); 482 $symbl = get_woocommerce_currency_symbol(); 483 $price = empty( $opt['ex_amount'] ) ? '0.00' : number_format( absint( $opt['ex_amount'] ), 2 ); 484 485 if ( empty( $_POST ) && empty( $meta['shipping_first_name'] ) && empty( $meta['shipping_country'] ) && 486 empty( $meta['billing_phone'] ) && empty( $meta['shipping_city'] ) ) { 480 $opt = get_option( 'shippo_options' ); 481 482 if ( isset( $opt['shipping_rate'] ) ) { 483 $uid = get_current_user_id(); 484 $meta = get_user_meta( $uid ); 485 $symbl = get_woocommerce_currency_symbol(); 486 $price = empty( $opt['ex_amount'] ) ? '0.00' : number_format( absint( $opt['ex_amount'] ), 2 ); 487 488 if ( empty( $_POST ) && empty( $meta['shipping_first_name'] ) && empty( $meta['shipping_country'] ) && 489 empty( $meta['billing_phone'] ) && empty( $meta['shipping_city'] ) ) { 490 echo " 491 <tr> 492 <th>shipping</th> 493 <td> 494 <div class='shippo-out'>" . esc_html( $price ) . ' ' . esc_html( $symbl ) . '</div> 495 </td> 496 </tr>'; 497 return; 498 } 499 500 $args = array(); 501 if ( empty( $_POST ) ) { 502 if ( ! empty( $meta['billing_first_name'] ) ) { 503 $args = array( 504 'name' => ( ! empty( $meta['billing_first_name'][0] ) ? $meta['billing_first_name'][0] : '' ) . ' ' . 505 ( ! empty( $meta['billing_last_name'][0] ) ? $meta['billing_last_name'][0] : '' ), 506 'company' => ! empty( $meta['billing_company'][0] ) ? $meta['billing_company'][0] : '', 507 'street1' => ( ! empty( $meta['billing_address_1'][0] ) ? $meta['billing_address_1'][0] : '' ) . 508 ' ' . 509 ( ! empty( $meta['billing_address_2'][0] ) ? $meta['billing_address_2'][0] : '' ), 510 'city' => ! empty( $meta['billing_city'][0] ) ? $meta['billing_city'][0] : '', 511 'state' => ! empty( $meta['billing_state'][0] ) ? $meta['billing_state'][0] : '', 512 'zip' => ! empty( $meta['billing_postcode'][0] ) ? $meta['billing_postcode'][0] : '', 513 'country' => ! empty( $meta['billing_country'][0] ) ? $meta['billing_country'][0] : '', 514 'phone' => ! empty( $meta['billing_phone'][0] ) ? $meta['billing_phone'][0] : '', 515 'email' => ! empty( $meta['billing_email'][0] ) ? $meta['billing_email'][0] : '', 516 ); 517 } 518 } else { 519 $data = ! empty( $_POST['post_data'] ) ? urldecode( wp_unslash( $_POST['post_data'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 520 parse_str( $data, $meta ); 521 $args = hippshipp_helper::get_live_rate_param( $meta ); 522 } 523 524 if ( ! empty( $args ) ) { 525 $rates = hippshipp_helper::get_order_rate( $args ); 526 } 527 528 if ( ! empty( $rates[0] ) ) { 529 $price += empty( $rates[0]->amount_local ) ? $rates[0]->amount : $rates[0]->amount_local; 530 $symbl = empty( $rates[0]->currency_local ) ? $symbl : $rates[0]->currency_local; 531 } 532 487 533 echo " 488 534 <tr> 489 <th>shipping</th> 490 <td> 491 <div class='shippo-out'>" . esc_html( $price ) . ' ' . esc_html( $symbl ) . '</div> 492 </td> 535 <th>Shipping</th> 536 <td style='width:50%;padding:0;'> 537 <div class='shippo-out'>" . 538 ( ( ! empty( $rates[0] ) ) ? 539 "<input type='radio' name='shipp_rate' value='" . esc_attr( $price ) . "' data-price='" . esc_attr( $price ) . "' checked='checked'/> 540 <label>" . number_format( $price, 2 ) . ' ' . esc_html( $symbl ) . '</label>' : 541 esc_html( $price ) . ' ' . esc_html( $symbl ) ) 542 . '</div> 543 <td> 493 544 </tr>'; 494 return; 495 } 496 497 $args = array(); 498 if ( empty( $_POST ) ) { 499 if ( ! empty( $meta['billing_first_name'] ) ) { 500 $args = array( 501 'name' => ( ! empty( $meta['billing_first_name'][0] ) ? $meta['billing_first_name'][0] : '' ) . ' ' . 502 ( ! empty( $meta['billing_last_name'][0] ) ? $meta['billing_last_name'][0] : '' ), 503 'company' => ! empty( $meta['billing_company'][0] ) ? $meta['billing_company'][0] : '', 504 'street1' => ( ! empty( $meta['billing_address_1'][0] ) ? $meta['billing_address_1'][0] : '' ) . 505 ' ' . 506 ( ! empty( $meta['billing_address_2'][0] ) ? $meta['billing_address_2'][0] : '' ), 507 'city' => ! empty( $meta['billing_city'][0] ) ? $meta['billing_city'][0] : '', 508 'state' => ! empty( $meta['billing_state'][0] ) ? $meta['billing_state'][0] : '', 509 'zip' => ! empty( $meta['billing_postcode'][0] ) ? $meta['billing_postcode'][0] : '', 510 'country' => ! empty( $meta['billing_country'][0] ) ? $meta['billing_country'][0] : '', 511 'phone' => ! empty( $meta['billing_phone'][0] ) ? $meta['billing_phone'][0] : '', 512 'email' => ! empty( $meta['billing_email'][0] ) ? $meta['billing_email'][0] : '', 513 ); 514 } 515 } else { 516 $data = ! empty( $_POST['post_data'] ) ? urldecode( wp_unslash( $_POST['post_data'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 517 parse_str( $data, $meta ); 518 $args = hippshipp_helper::get_live_rate_param( $meta ); 519 } 520 521 if ( ! empty( $args ) ) { 522 $rates = hippshipp_helper::get_order_rate( $args ); 523 } 524 525 if ( ! empty( $rates[0] ) ) { 526 $price += empty( $rates[0]->amount_local ) ? $rates[0]->amount : $rates[0]->amount_local; 527 $symbl = empty( $rates[0]->currency_local ) ? $symbl : $rates[0]->currency_local; 528 } 529 530 echo " 531 <tr> 532 <th>Shipping</th> 533 <td style='width:50%;padding:0;'> 534 <div class='shippo-out'>" . 535 ( ( ! empty( $rates[0] ) ) ? 536 "<input type='radio' name='shipp_rate' value='" . esc_attr( $price ) . "' data-price='" . esc_attr( $price ) . "' checked='checked'/> 537 <label>" . number_format( $price, 2 ) . ' ' . esc_html( $symbl ) . '</label>' : 538 esc_html( $price ) . ' ' . esc_html( $symbl ) ) 539 . '</div> 540 <td> 541 </tr>'; 545 } 542 546 } 543 547 -
hippoo-shippo-integration-for-woocommerce/trunk/inc/shippo-api.php
r3357076 r3359066 98 98 $opt = get_option( 'shippo_options', array() ); 99 99 if ( is_array( $parcel ) ) { 100 $parcel['distance_unit'] = get_option( 'woocommerce_dimension_unit' );101 $parcel['mass_unit'] = get_option( 'woocommerce_weight_unit' );100 $parcel['distance_unit'] = $parcel['distance_unit'] ?? get_option( 'woocommerce_dimension_unit' ); 101 $parcel['mass_unit'] = $parcel['weight_unit'] ?? get_option( 'woocommerce_weight_unit' ); 102 102 } else { 103 103 $parobj = hippshipp_helper::get_parcel(); -
hippoo-shippo-integration-for-woocommerce/trunk/inc/web-api.php
r3357076 r3359066 211 211 if ( empty( $package['template'] ) ) { 212 212 $shipp[2]['tplbox'] = array( 213 'weight' => $package['weight'] ?? $shipp[2]['tplbox']['weight'], 214 'length' => $package['dimensions']['length'] ?? $shipp[2]['tplbox']['length'], 215 'width' => $package['dimensions']['width'] ?? $shipp[2]['tplbox']['width'], 216 'height' => $package['dimensions']['height'] ?? $shipp[2]['tplbox']['height'], 213 'weight' => $package['weight'] ?? $shipp[2]['tplbox']['weight'], 214 'weight_unit' => $package['weight_unit'] ?? $shipp[2]['tplbox']['weight_unit'], 215 'length' => $package['dimensions']['length'] ?? $shipp[2]['tplbox']['length'], 216 'width' => $package['dimensions']['width'] ?? $shipp[2]['tplbox']['width'], 217 'height' => $package['dimensions']['height'] ?? $shipp[2]['tplbox']['height'], 218 'distance_unit' => $package['dimensions']['unit'] ?? $shipp[2]['tplbox']['distance_unit'], 217 219 ); 218 220 } … … 297 299 'shipment_purpose' => $data['shipment_purpose'], 298 300 ) 299 );301 ); 300 302 301 303 if( ! isset( $declare->object_id ) ) { 302 return new WP_Error( 'update_custome_failure', 'Custome is not valid.', array( 'error' => reset( $declare ), 'status' => 400 ) ); 304 $error_message = hippshipp_helper::extract_error_message( reset( $declare ) ); 305 return new WP_Error( 'update_custome_failure', $error_message ?: 'Unknown error', array( 'status' => 400 ) ); 303 306 } 304 307 … … 347 350 348 351 if ( ! isset( $shippment->object_id ) ) { 349 return new WP_Error( 'shippment_simple_failure', 'Shipping is not valid.', array( 'error' => is_array( $shippment ) ? reset( $shippment ) : $shippment, 'status' => 400 ) ); 352 $error_message = hippshipp_helper::extract_error_message( $shippment ); 353 return new WP_Error( 'shippment_simple_failure', $error_message ?: 'Unknown error', array( 'status' => 400 ) ); 350 354 } 351 355 … … 353 357 354 358 if ( empty( $rates ) ) { 355 return new WP_Error( 'shippment_rates_failure', 'Shipping rates not found.', array( 'error' => $shippment->messages[0]->text, 'status' => 400 ) ); 359 $error_message = hippshipp_helper::extract_error_message( $shippment->messages[0]->text ?? 'No rates available' ); 360 return new WP_Error( 'shippment_rates_failure', $error_message, array( 'status' => 400 ) ); 356 361 } 357 362 … … 400 405 401 406 if ( ! isset( $label->tracking_number ) ) { 402 return new WP_Error( 'get_label_failure', 'Label is not valid.', array( 'error' => reset( $label )[0], 'status' => 400 ) ); 407 $error_message = hippshipp_helper::extract_error_message( reset( $label )[0] ); 408 return new WP_Error( 'get_label_failure', $error_message ?: 'Unknown error', array( 'status' => 400 ) ); 403 409 } 404 410 405 411 if ( empty( $label->tracking_number ) ) { 406 return new WP_Error( 'get_label_failure', 'Label is not valid.', array( 'error' => $label->messages[0]->text, 'status' => 400 ) ); 412 $error_message = hippshipp_helper::extract_error_message( $shippment->messages[0]->text ?? 'No label available' ); 413 return new WP_Error( 'get_label_failure', $error_message, array( 'status' => 400 ) ); 407 414 } 408 415 -
hippoo-shippo-integration-for-woocommerce/trunk/readme.txt
r3357076 r3359066 2 2 3 3 Contributors: Hippooo 4 Tags: WooCommerce, Shippo, shipping, labels, e-commerce, carriers, goshippo, WooCommerce label generate, shipping rates, WooCommerce shipping, carrier integration, shipping label generator , hippoo WooCommerce app4 Tags: WooCommerce, Shippo, shipping, labels, e-commerce, carriers, goshippo, WooCommerce label generate, shipping rates, WooCommerce shipping, carrier integration, shipping label generator 5 5 Requires at least: 5.8 6 6 Tested up to: 6.7 7 7 Requires PHP: 7.4 8 Stable tag: 1.1. 08 Stable tag: 1.1.1 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 95 95 == Changelog == 96 96 97 = 1.1.0 = 98 * Added REST API to integrate with Hippoo WooCommerce app. 99 * Bug fixes. 100 * Compatibility with High-Performance Order Storage (HPOS). 97 = 1.1.1 = 98 99 * Minor Improvements 101 100 102 101 = 1.0.0 = 102 103 103 * Initial release. 104 104 * Seamless Shippo integration with WooCommerce.
Note: See TracChangeset
for help on using the changeset viewer.