Plugin Directory

Changeset 3359066


Ignore:
Timestamp:
09/10/2025 09:49:51 AM (7 months ago)
Author:
hippooo
Message:

1.1.1

Location:
hippoo-shippo-integration-for-woocommerce/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • hippoo-shippo-integration-for-woocommerce/trunk/hippoo-shippo.php

    r3357076 r3359066  
    55Description: 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.
    66Short Description: Generate Shippo carrier labels inside WooCommerce Admin with real-time shipping rates at checkout.
    7 Version: 1.1.0
     7Version: 1.1.1
    88Author: Hippoo Team
    99License: GPLv2 or later
     
    2626}
    2727
    28 define( 'hippshipp_version', '1.1.0' );
     28define( 'hippshipp_version', '1.1.1' );
    2929define( 'hippshipp__FILE__', __FILE__ );
    3030define( 'hippshipp_path', plugin_dir_path( __FILE__ ) );
  • hippoo-shippo-integration-for-woocommerce/trunk/inc/helper.php

    r3357076 r3359066  
    249249        // phpcs:enable
    250250    }
     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    }
    251286}
  • hippoo-shippo-integration-for-woocommerce/trunk/inc/hooks.php

    r3357076 r3359066  
    146146        if (
    147147            ( $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' )
    149150        ) {
    150151            wp_enqueue_script( 'jquery' );
     
    477478        }
    478479
    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
    487533            echo "
    488534            <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>
    493544            </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        }
    542546    }
    543547
  • hippoo-shippo-integration-for-woocommerce/trunk/inc/shippo-api.php

    r3357076 r3359066  
    9898        $opt = get_option( 'shippo_options', array() );
    9999        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' );
    102102        } else {
    103103            $parobj = hippshipp_helper::get_parcel();
  • hippoo-shippo-integration-for-woocommerce/trunk/inc/web-api.php

    r3357076 r3359066  
    211211        if ( empty( $package['template'] ) ) {
    212212            $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'],
    217219            );
    218220        }
     
    297299                'shipment_purpose'    => $data['shipment_purpose'],
    298300            )
    299          );
     301        );
    300302
    301303        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 ) );
    303306        }
    304307
     
    347350
    348351        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 ) );
    350354        }
    351355
     
    353357
    354358        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 ) );
    356361        }
    357362
     
    400405
    401406        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 ) );
    403409        }
    404410
    405411        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 ) );
    407414        }
    408415
  • hippoo-shippo-integration-for-woocommerce/trunk/readme.txt

    r3357076 r3359066  
    22
    33Contributors: 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 app
     4Tags: WooCommerce, Shippo, shipping, labels, e-commerce, carriers, goshippo, WooCommerce label generate, shipping rates, WooCommerce shipping, carrier integration, shipping label generator
    55Requires at least: 5.8
    66Tested up to: 6.7
    77Requires PHP: 7.4
    8 Stable tag: 1.1.0
     8Stable tag: 1.1.1
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    9595== Changelog ==
    9696
    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
    101100
    102101= 1.0.0 =
     102
    103103* Initial release.
    104104* Seamless Shippo integration with WooCommerce.
Note: See TracChangeset for help on using the changeset viewer.