Plugin Directory

Changeset 3480704


Ignore:
Timestamp:
03/11/2026 11:02:15 PM (3 weeks ago)
Author:
sendbox
Message:

Version 5.5.5: Show all courier rates at checkout instead of single max/min fee. Pre-select customer's chosen courier in order metabox.

Location:
sendbox-shipping
Files:
17 deleted
8 edited
13 copied

Legend:

Unmodified
Added
Removed
  • sendbox-shipping/tags/5.5.5/README.txt

    r3478501 r3480704  
    55Requires at least: 6.0
    66Tested up to: 6.9
    7 Stable tag: 5.5.4
     7Stable tag: 5.5.5
    88Requires PHP: 7.4
    99License: GPLv2 or later
  • sendbox-shipping/tags/5.5.5/assets/js/admin-order.js

    r3478358 r3480704  
    1212
    1313        // Courier selection: update fee display
    14         $("#wooss_selected_courier").on("change", function () {
    15             var option = this.options[this.selectedIndex];
     14        function updateCourierFee() {
     15            var select = document.getElementById("wooss_selected_courier");
     16            if (!select) return;
     17            var option = select.options[select.selectedIndex];
    1618            var price = option ? option.getAttribute("data-courier-price") : "";
    1719            var feeEl = document.getElementById("dabs");
     
    2022                feeEl.style.color = "#ed2f59";
    2123            }
    22         });
     24        }
     25
     26        // Show fee on load if a courier is pre-selected
     27        updateCourierFee();
     28
     29        $("#wooss_selected_courier").on("change", updateCourierFee);
    2330
    2431        // Country dropdown change: load states
  • sendbox-shipping/tags/5.5.5/src/Admin/OrderMetabox.php

    r3478358 r3480704  
    156156        }
    157157
     158        // Get the rate code the customer selected at checkout.
     159        $selected_rate_code = '';
     160        $selected_rate_key  = '';
     161        foreach ( $order->get_items( 'shipping' ) as $shipping_item ) {
     162            $code = $shipping_item->get_meta( 'wooss_rate_code' );
     163            $key  = $shipping_item->get_meta( 'wooss_rate_key' );
     164            if ( ! empty( $code ) ) {
     165                $selected_rate_code = $code;
     166                $selected_rate_key  = $key;
     167                break;
     168            }
     169        }
     170
    158171        $wc_countries    = WC()->countries->get_countries();
    159172        $dest_country_code = ! empty( $dest_country ) ? $dest_country : 'NG';
     
    189202            <select id="wooss_selected_courier">
    190203                <option value=""><?php esc_html_e( 'Select a courier...', 'wooss' ); ?></option>
    191                 <?php foreach ( $rates as $rate ) : ?>
     204                <?php foreach ( $rates as $rate ) :
     205                    $rate_code_val = isset( $rate->code ) ? $rate->code : '';
     206                ?>
    192207                    <option data-courier-price="<?php echo esc_attr( isset( $rate->fee ) ? $rate->fee : '' ); ?>"
    193208                            data-courier-key="<?php echo esc_attr( isset( $rate->key ) ? $rate->key : '' ); ?>"
    194                             value="<?php echo esc_attr( isset( $rate->code ) ? $rate->code : '' ); ?>">
     209                            value="<?php echo esc_attr( $rate_code_val ); ?>"
     210                            <?php selected( $selected_rate_code, $rate_code_val ); ?>>
    195211                        <?php echo esc_html( sprintf(
    196212                            '%s - %s%s',
  • sendbox-shipping/tags/5.5.5/src/ShippingMethod.php

    r3478358 r3480704  
    159159        }
    160160
    161         $wooss_rates_type = isset( $sendbox_data['wooss_rates_type'] ) ? $sendbox_data['wooss_rates_type'] : 'maximum';
    162161        $wooss_extra_fees = isset( $sendbox_data['wooss_extra_fees'] ) ? (float) $sendbox_data['wooss_extra_fees'] : 0;
    163         $quotes_fee       = $this->extract_fee( $response, $wooss_rates_type );
    164         $quoted_fee       = $quotes_fee + $wooss_extra_fees;
    165 
    166         if ( (int) $quoted_fee === 0 ) {
    167             $response   = $client->get_delivery_quote( $payload );
    168             $quotes_fee = $this->extract_fee( $response, $wooss_rates_type );
    169             $quoted_fee = $quotes_fee + $wooss_extra_fees;
    170         }
    171 
    172         // Debug: log fee extraction details.
    173         if ( function_exists( 'wc_get_logger' ) ) {
    174             $body = $response && isset( $response->body ) ? $response->body : null;
    175             wc_get_logger()->debug( sprintf(
    176                 'Fee extraction: rates_type=%s, has_body=%s, has_rates=%s, rates_is_array=%s, has_rate=%s, quotes_fee=%s, quoted_fee=%s, body_keys=%s',
    177                 $wooss_rates_type,
    178                 $body ? 'yes' : 'no',
    179                 isset( $body->rates ) ? 'yes' : 'no',
    180                 isset( $body->rates ) && is_array( $body->rates ) ? 'yes' : 'no',
    181                 isset( $body->rate ) ? 'yes' : 'no',
    182                 $quotes_fee,
    183                 $quoted_fee,
    184                 $body ? wp_json_encode( array_keys( (array) $body ) ) : 'null'
    185             ), array( 'source' => 'sendbox-shipping' ) );
    186         }
    187 
    188         $this->add_rate( array(
    189             'id'      => $this->id,
    190             'label'   => $this->title,
    191             'cost'    => $quoted_fee,
    192             'package' => $package,
    193         ) );
    194     }
    195 
    196     private function extract_fee( $response, $rates_type ) {
     162        $rates            = $this->extract_rates( $response );
     163
     164        // Retry once if no rates returned.
     165        if ( empty( $rates ) ) {
     166            $response = $client->get_delivery_quote( $payload );
     167            $rates    = $this->extract_rates( $response );
     168        }
     169
     170        if ( empty( $rates ) ) {
     171            $this->log( 'No shipping rates returned from Sendbox API.' );
     172            return;
     173        }
     174
     175        foreach ( $rates as $index => $rate ) {
     176            $fee  = isset( $rate->fee ) ? (float) $rate->fee : 0;
     177            $name = isset( $rate->name ) ? $rate->name : '';
     178            $code = isset( $rate->code ) ? $rate->code : '';
     179
     180            if ( $fee <= 0 ) {
     181                continue;
     182            }
     183
     184            $label = ! empty( $name ) ? $name : $this->title;
     185            $cost  = $fee + $wooss_extra_fees;
     186            $rate_id = $this->id . '_' . ( ! empty( $code ) ? sanitize_title( $code ) : $index );
     187
     188            $this->add_rate( array(
     189                'id'        => $rate_id,
     190                'label'     => $label,
     191                'cost'      => $cost,
     192                'package'   => $package,
     193                'meta_data' => array(
     194                    'wooss_rate_code' => $code,
     195                    'wooss_rate_key'  => isset( $rate->key ) ? $rate->key : '',
     196                ),
     197            ) );
     198        }
     199    }
     200
     201    private function extract_rates( $response ) {
    197202        if ( ! $response || ! isset( $response->body ) ) {
    198             return 0;
     203            return array();
    199204        }
    200205
    201206        $body = $response->body;
    202207
    203         // Legacy fields.
    204         if ( 'maximum' === $rates_type && isset( $body->max_quoted_fee ) ) {
    205             return (float) $body->max_quoted_fee;
    206         }
    207         if ( 'minimum' === $rates_type && isset( $body->min_quoted_fee ) ) {
    208             return (float) $body->min_quoted_fee;
    209         }
    210 
    211         // Current API returns rates as an array of rate objects with a fee field.
     208        // Current API returns rates as an array of rate objects.
    212209        if ( ! empty( $body->rates ) && is_array( $body->rates ) ) {
    213             $fees = array_map( function ( $rate ) {
    214                 return isset( $rate->fee ) ? (float) $rate->fee : 0;
    215             }, $body->rates );
    216 
    217             $fees = array_filter( $fees );
    218             if ( ! empty( $fees ) ) {
    219                 return 'maximum' === $rates_type ? max( $fees ) : min( $fees );
    220             }
    221         }
    222 
    223         // Single rate object.
    224         if ( isset( $body->rate->fee ) ) {
    225             return (float) $body->rate->fee;
    226         }
    227 
    228         return 0;
     210            return $body->rates;
     211        }
     212
     213        // Single rate object — wrap in array.
     214        if ( isset( $body->rate ) && isset( $body->rate->fee ) ) {
     215            return array( $body->rate );
     216        }
     217
     218        return array();
    229219    }
    230220
  • sendbox-shipping/tags/5.5.5/wooss.php

    r3478501 r3480704  
    44 * Plugin URI:        https://sendbox.co/
    55 * Description:       WooCommerce shipping integration with Sendbox — ship from your store to anywhere in the world.
    6  * Version:           5.5.4
     6 * Version:           5.5.5
    77 * Author:            Sendbox
    88 * Author URI:        https://sendbox.co/
     
    2323}
    2424
    25 define( 'WOOSS_VERSION', '5.5.4' );
     25define( 'WOOSS_VERSION', '5.5.5' );
    2626define( 'WOOSS_PLUGIN_FILE', __FILE__ );
    2727define( 'WOOSS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
  • sendbox-shipping/trunk/README.txt

    r3478501 r3480704  
    55Requires at least: 6.0
    66Tested up to: 6.9
    7 Stable tag: 5.5.4
     7Stable tag: 5.5.5
    88Requires PHP: 7.4
    99License: GPLv2 or later
  • sendbox-shipping/trunk/assets/js/admin-order.js

    r3478358 r3480704  
    1212
    1313        // Courier selection: update fee display
    14         $("#wooss_selected_courier").on("change", function () {
    15             var option = this.options[this.selectedIndex];
     14        function updateCourierFee() {
     15            var select = document.getElementById("wooss_selected_courier");
     16            if (!select) return;
     17            var option = select.options[select.selectedIndex];
    1618            var price = option ? option.getAttribute("data-courier-price") : "";
    1719            var feeEl = document.getElementById("dabs");
     
    2022                feeEl.style.color = "#ed2f59";
    2123            }
    22         });
     24        }
     25
     26        // Show fee on load if a courier is pre-selected
     27        updateCourierFee();
     28
     29        $("#wooss_selected_courier").on("change", updateCourierFee);
    2330
    2431        // Country dropdown change: load states
  • sendbox-shipping/trunk/src/Admin/OrderMetabox.php

    r3478358 r3480704  
    156156        }
    157157
     158        // Get the rate code the customer selected at checkout.
     159        $selected_rate_code = '';
     160        $selected_rate_key  = '';
     161        foreach ( $order->get_items( 'shipping' ) as $shipping_item ) {
     162            $code = $shipping_item->get_meta( 'wooss_rate_code' );
     163            $key  = $shipping_item->get_meta( 'wooss_rate_key' );
     164            if ( ! empty( $code ) ) {
     165                $selected_rate_code = $code;
     166                $selected_rate_key  = $key;
     167                break;
     168            }
     169        }
     170
    158171        $wc_countries    = WC()->countries->get_countries();
    159172        $dest_country_code = ! empty( $dest_country ) ? $dest_country : 'NG';
     
    189202            <select id="wooss_selected_courier">
    190203                <option value=""><?php esc_html_e( 'Select a courier...', 'wooss' ); ?></option>
    191                 <?php foreach ( $rates as $rate ) : ?>
     204                <?php foreach ( $rates as $rate ) :
     205                    $rate_code_val = isset( $rate->code ) ? $rate->code : '';
     206                ?>
    192207                    <option data-courier-price="<?php echo esc_attr( isset( $rate->fee ) ? $rate->fee : '' ); ?>"
    193208                            data-courier-key="<?php echo esc_attr( isset( $rate->key ) ? $rate->key : '' ); ?>"
    194                             value="<?php echo esc_attr( isset( $rate->code ) ? $rate->code : '' ); ?>">
     209                            value="<?php echo esc_attr( $rate_code_val ); ?>"
     210                            <?php selected( $selected_rate_code, $rate_code_val ); ?>>
    195211                        <?php echo esc_html( sprintf(
    196212                            '%s - %s%s',
  • sendbox-shipping/trunk/src/ShippingMethod.php

    r3478358 r3480704  
    159159        }
    160160
    161         $wooss_rates_type = isset( $sendbox_data['wooss_rates_type'] ) ? $sendbox_data['wooss_rates_type'] : 'maximum';
    162161        $wooss_extra_fees = isset( $sendbox_data['wooss_extra_fees'] ) ? (float) $sendbox_data['wooss_extra_fees'] : 0;
    163         $quotes_fee       = $this->extract_fee( $response, $wooss_rates_type );
    164         $quoted_fee       = $quotes_fee + $wooss_extra_fees;
    165 
    166         if ( (int) $quoted_fee === 0 ) {
    167             $response   = $client->get_delivery_quote( $payload );
    168             $quotes_fee = $this->extract_fee( $response, $wooss_rates_type );
    169             $quoted_fee = $quotes_fee + $wooss_extra_fees;
    170         }
    171 
    172         // Debug: log fee extraction details.
    173         if ( function_exists( 'wc_get_logger' ) ) {
    174             $body = $response && isset( $response->body ) ? $response->body : null;
    175             wc_get_logger()->debug( sprintf(
    176                 'Fee extraction: rates_type=%s, has_body=%s, has_rates=%s, rates_is_array=%s, has_rate=%s, quotes_fee=%s, quoted_fee=%s, body_keys=%s',
    177                 $wooss_rates_type,
    178                 $body ? 'yes' : 'no',
    179                 isset( $body->rates ) ? 'yes' : 'no',
    180                 isset( $body->rates ) && is_array( $body->rates ) ? 'yes' : 'no',
    181                 isset( $body->rate ) ? 'yes' : 'no',
    182                 $quotes_fee,
    183                 $quoted_fee,
    184                 $body ? wp_json_encode( array_keys( (array) $body ) ) : 'null'
    185             ), array( 'source' => 'sendbox-shipping' ) );
    186         }
    187 
    188         $this->add_rate( array(
    189             'id'      => $this->id,
    190             'label'   => $this->title,
    191             'cost'    => $quoted_fee,
    192             'package' => $package,
    193         ) );
    194     }
    195 
    196     private function extract_fee( $response, $rates_type ) {
     162        $rates            = $this->extract_rates( $response );
     163
     164        // Retry once if no rates returned.
     165        if ( empty( $rates ) ) {
     166            $response = $client->get_delivery_quote( $payload );
     167            $rates    = $this->extract_rates( $response );
     168        }
     169
     170        if ( empty( $rates ) ) {
     171            $this->log( 'No shipping rates returned from Sendbox API.' );
     172            return;
     173        }
     174
     175        foreach ( $rates as $index => $rate ) {
     176            $fee  = isset( $rate->fee ) ? (float) $rate->fee : 0;
     177            $name = isset( $rate->name ) ? $rate->name : '';
     178            $code = isset( $rate->code ) ? $rate->code : '';
     179
     180            if ( $fee <= 0 ) {
     181                continue;
     182            }
     183
     184            $label = ! empty( $name ) ? $name : $this->title;
     185            $cost  = $fee + $wooss_extra_fees;
     186            $rate_id = $this->id . '_' . ( ! empty( $code ) ? sanitize_title( $code ) : $index );
     187
     188            $this->add_rate( array(
     189                'id'        => $rate_id,
     190                'label'     => $label,
     191                'cost'      => $cost,
     192                'package'   => $package,
     193                'meta_data' => array(
     194                    'wooss_rate_code' => $code,
     195                    'wooss_rate_key'  => isset( $rate->key ) ? $rate->key : '',
     196                ),
     197            ) );
     198        }
     199    }
     200
     201    private function extract_rates( $response ) {
    197202        if ( ! $response || ! isset( $response->body ) ) {
    198             return 0;
     203            return array();
    199204        }
    200205
    201206        $body = $response->body;
    202207
    203         // Legacy fields.
    204         if ( 'maximum' === $rates_type && isset( $body->max_quoted_fee ) ) {
    205             return (float) $body->max_quoted_fee;
    206         }
    207         if ( 'minimum' === $rates_type && isset( $body->min_quoted_fee ) ) {
    208             return (float) $body->min_quoted_fee;
    209         }
    210 
    211         // Current API returns rates as an array of rate objects with a fee field.
     208        // Current API returns rates as an array of rate objects.
    212209        if ( ! empty( $body->rates ) && is_array( $body->rates ) ) {
    213             $fees = array_map( function ( $rate ) {
    214                 return isset( $rate->fee ) ? (float) $rate->fee : 0;
    215             }, $body->rates );
    216 
    217             $fees = array_filter( $fees );
    218             if ( ! empty( $fees ) ) {
    219                 return 'maximum' === $rates_type ? max( $fees ) : min( $fees );
    220             }
    221         }
    222 
    223         // Single rate object.
    224         if ( isset( $body->rate->fee ) ) {
    225             return (float) $body->rate->fee;
    226         }
    227 
    228         return 0;
     210            return $body->rates;
     211        }
     212
     213        // Single rate object — wrap in array.
     214        if ( isset( $body->rate ) && isset( $body->rate->fee ) ) {
     215            return array( $body->rate );
     216        }
     217
     218        return array();
    229219    }
    230220
  • sendbox-shipping/trunk/wooss.php

    r3478501 r3480704  
    44 * Plugin URI:        https://sendbox.co/
    55 * Description:       WooCommerce shipping integration with Sendbox — ship from your store to anywhere in the world.
    6  * Version:           5.5.4
     6 * Version:           5.5.5
    77 * Author:            Sendbox
    88 * Author URI:        https://sendbox.co/
     
    2323}
    2424
    25 define( 'WOOSS_VERSION', '5.5.4' );
     25define( 'WOOSS_VERSION', '5.5.5' );
    2626define( 'WOOSS_PLUGIN_FILE', __FILE__ );
    2727define( 'WOOSS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.