Plugin Directory

Changeset 3372485


Ignore:
Timestamp:
10/03/2025 04:54:17 PM (6 months ago)
Author:
hippooo
Message:

1.1.3

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

Legend:

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

    r3360756 r3372485  
    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.2
     7Version: 1.1.3
    88Author: Hippoo Team
    99License: GPLv2 or later
     
    2626}
    2727
    28 define( 'hippshipp_version', '1.1.1' );
     28define( 'hippshipp_version', '1.1.3' );
    2929define( 'hippshipp__FILE__', __FILE__ );
    3030define( 'hippshipp_path', plugin_dir_path( __FILE__ ) );
  • hippoo-shippo-integration-for-woocommerce/trunk/inc/hooks.php

    r3360756 r3372485  
    1212        add_action( 'woocommerce_admin_field_shippo_options_table', array( $this, 'woocommerce_admin_field_shippo_options_table' ), 10, 1 );
    1313        add_action( 'woocommerce_update_option_shippo_options_table', array( $this, 'woocommerce_update_option_shippo_options_table' ), 10, 1 );
    14         // save track code to customer order note
    15         add_action( 'woocommerce_thankyou', array( $this, 'woocommerce_thankyou' ), 10, 1 );
    1614        // show list of shippment
    1715        add_action( 'woocommerce_review_order_after_shipping', array( $this, 'woocommerce_review_order_before_submit' ) );
     
    372370
    373371    function woocommerce_update_option_shippo_options_table( $value ) {
    374 
    375372        $shippo_api = new hippshipp_api();
    376373
     
    455452    }
    456453
    457     function woocommerce_thankyou( $order_id ) {
    458 
    459         $opt = get_option( 'shippo_options' );
    460         // $objct = hippshipp_helper::get_order_meta($order_id,'shipp_rate');
    461         // $trans = (new hippshipp_api)->transactions($objct);
    462         // hippshipp_helper::update_order_meta($order_id,'shipp_label',$trans);
    463 
    464         $order = new \WC_Order( $order_id );
    465         /*
    466         if(empty($opt['en_shippo']) or empty($opt['tracking_code']))
    467         return;
    468         $order = wc_get_order($order_id);
    469         if($trans->object_state == 'VALID')
    470             $order->set_customer_note("Your post Tracking code is:{$trans->tracking_number}");
    471             // $order->add_order_note($note);
    472         else
    473         $order->add_order_note('problem to get tracking code.');
    474         $order->save(); */
    475     }
    476 
    477454    function woocommerce_review_order_before_submit() {
    478455        if ( isset( $_POST['shippo_nonce'] ) and ! wp_verify_nonce( sanitize_key( $_POST['shippo_nonce'] ), 'shippo_action' ) ) {
     
    481458
    482459        $opt = get_option( 'shippo_options' );
    483 
    484         if ( isset( $opt['shipping_rate'] ) ) {
    485             $uid   = get_current_user_id();
    486             $meta  = get_user_meta( $uid );
    487             $symbl = get_woocommerce_currency_symbol();
    488             $price = empty( $opt['ex_amount'] ) ? '0.00' : number_format( absint( $opt['ex_amount'] ), 2 );
    489 
    490             if ( empty( $_POST ) && empty( $meta['shipping_first_name'] ) && empty( $meta['shipping_country'] ) &&
    491                 empty( $meta['billing_phone'] ) && empty( $meta['shipping_city'] ) ) {
    492                 echo "
    493                 <tr>
    494                     <th>shipping</th>
    495                     <td>
    496                         <div class='shippo-out'>" . esc_html( $price ) . ' ' . esc_html( $symbl ) . '</div>
    497                     </td>
    498                 </tr>';
    499                 return;
    500             }
    501 
    502             $args = array();
    503             if ( empty( $_POST ) ) {
    504                 if ( ! empty( $meta['billing_first_name'] ) ) {
    505                     $args = array(
    506                         'name'    => ( ! empty( $meta['billing_first_name'][0] ) ? $meta['billing_first_name'][0] : '' ) . ' ' .
    507                                     ( ! empty( $meta['billing_last_name'][0] ) ? $meta['billing_last_name'][0] : '' ),
    508                         'company' => ! empty( $meta['billing_company'][0] ) ? $meta['billing_company'][0] : '',
    509                         'street1' => ( ! empty( $meta['billing_address_1'][0] ) ? $meta['billing_address_1'][0] : '' ) .
    510                                     ' ' .
    511                                     ( ! empty( $meta['billing_address_2'][0] ) ? $meta['billing_address_2'][0] : '' ),
    512                         'city'    => ! empty( $meta['billing_city'][0] ) ? $meta['billing_city'][0] : '',
    513                         'state'   => ! empty( $meta['billing_state'][0] ) ? $meta['billing_state'][0] : '',
    514                         'zip'     => ! empty( $meta['billing_postcode'][0] ) ? $meta['billing_postcode'][0] : '',
    515                         'country' => ! empty( $meta['billing_country'][0] ) ? $meta['billing_country'][0] : '',
    516                         'phone'   => ! empty( $meta['billing_phone'][0] ) ? $meta['billing_phone'][0] : '',
    517                         'email'   => ! empty( $meta['billing_email'][0] ) ? $meta['billing_email'][0] : '',
    518                     );
    519                 }
    520             } else {
    521                 $data = ! empty( $_POST['post_data'] ) ? urldecode( wp_unslash( $_POST['post_data'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    522                 parse_str( $data, $meta );
    523                 $args = hippshipp_helper::get_live_rate_param( $meta );
    524             }
    525 
    526             if ( ! empty( $args ) ) {
    527                 $rates = hippshipp_helper::get_order_rate( $args );
    528             }
    529 
    530             if ( ! empty( $rates[0] ) ) {
    531                 $price += empty( $rates[0]->amount_local ) ? $rates[0]->amount : $rates[0]->amount_local;
    532                 $symbl  = empty( $rates[0]->currency_local ) ? $symbl : $rates[0]->currency_local;
    533             }
    534 
     460        $uid   = get_current_user_id();
     461        $meta  = get_user_meta( $uid );
     462        $symbl = get_woocommerce_currency_symbol();
     463        $price = empty( $opt['ex_amount'] ) ? '0.00' : number_format( absint( $opt['ex_amount'] ), 2 );
     464
     465        if ( empty( $_POST ) && empty( $meta['shipping_first_name'] ) && empty( $meta['shipping_country'] ) &&
     466            empty( $meta['billing_phone'] ) && empty( $meta['shipping_city'] ) ) {
     467            echo "
     468            <tr>
     469                <th>Shipping</th>
     470                <td>
     471                    <div class='shippo-out'>" . esc_html( $price ) . ' ' . esc_html( $symbl ) . '</div>
     472                </td>
     473            </tr>';
     474            return;
     475        }
     476
     477        $args = array();
     478        if ( empty( $_POST ) ) {
     479            if ( ! empty( $meta['billing_first_name'] ) ) {
     480                $args = array(
     481                    'name'    => ( ! empty( $meta['billing_first_name'][0] ) ? $meta['billing_first_name'][0] : '' ) . ' ' .
     482                                ( ! empty( $meta['billing_last_name'][0] ) ? $meta['billing_last_name'][0] : '' ),
     483                    'company' => ! empty( $meta['billing_company'][0] ) ? $meta['billing_company'][0] : '',
     484                    'street1' => ( ! empty( $meta['billing_address_1'][0] ) ? $meta['billing_address_1'][0] : '' ) .
     485                                ' ' .
     486                                ( ! empty( $meta['billing_address_2'][0] ) ? $meta['billing_address_2'][0] : '' ),
     487                    'city'    => ! empty( $meta['billing_city'][0] ) ? $meta['billing_city'][0] : '',
     488                    'state'   => ! empty( $meta['billing_state'][0] ) ? $meta['billing_state'][0] : '',
     489                    'zip'     => ! empty( $meta['billing_postcode'][0] ) ? $meta['billing_postcode'][0] : '',
     490                    'country' => ! empty( $meta['billing_country'][0] ) ? $meta['billing_country'][0] : '',
     491                    'phone'   => ! empty( $meta['billing_phone'][0] ) ? $meta['billing_phone'][0] : '',
     492                    'email'   => ! empty( $meta['billing_email'][0] ) ? $meta['billing_email'][0] : '',
     493                );
     494            }
     495        } else {
     496            $data = ! empty( $_POST['post_data'] ) ? urldecode( wp_unslash( $_POST['post_data'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
     497            parse_str( $data, $meta );
     498            $args = hippshipp_helper::get_live_rate_param( $meta );
     499        }
     500
     501        $rates = array();
     502        if ( ! empty( $args ) ) {
     503            $rates = hippshipp_helper::get_order_rate( $args );
     504        }
     505
     506        if ( ! empty( $rates ) ) {
     507            $_SESSION['shippo_shippment'] = array( $rates, $args );
     508            $price += empty( $rates[0]->amount_local ) ? $rates[0]->amount : $rates[0]->amount_local;
     509            $symbl  = empty( $rates[0]->currency_local ) ? $symbl : $rates[0]->currency_local;
     510        }
     511
     512        if ( isset( $opt['en_shippo'] ) && isset( $opt['shipping_rate'] ) ) {
    535513            echo "
    536514            <tr>
     
    549527
    550528    function woocommerce_new_order( $order_id ) {
    551 
    552529        $opt = get_option( 'shippo_options' );
    553 
    554         if ( isset( $opt['shipping_rate'] ) ) {
    555             if ( ! isset( $_SESSION['shippo_shippment'] ) ) {
    556                 return;
    557             }
    558            
     530        $order = new \WC_Order( $order_id );
     531
     532        if ( isset( $opt['en_shippo'] ) && isset( $_SESSION['shippo_shippment'] ) ) {
    559533            $shippment = $_SESSION['shippo_shippment']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    560534            $shippment_amount_local = isset( $shippment[0][0]->amount_local ) ? floatval( sanitize_text_field( $shippment[0][0]->amount_local ) ) : 0;
     
    569543
    570544            unset( $_SESSION['shippo_shippment'] );
    571             $order = new \WC_Order( $order_id );
    572545
    573546            $total = $order->get_total();
     
    584557
    585558            $order->save();
     559        } else {
     560            $order_data = $order->get_data();
     561            $meta = array(
     562                'ship_to_different_address' => ! empty( $order_data['shipping']['address_1'] ) && $order_data['shipping']['address_1'] !== $order_data['billing']['address_1'],
     563                'shipping_first_name' => $order_data['shipping']['first_name'] ?: $order_data['billing']['first_name'],
     564                'shipping_last_name' => $order_data['shipping']['last_name'] ?: $order_data['billing']['last_name'],
     565                'shipping_company' => $order_data['shipping']['company'] ?: $order_data['billing']['company'],
     566                'shipping_address_1' => $order_data['shipping']['address_1'] ?: $order_data['billing']['address_1'],
     567                'shipping_address_2' => $order_data['shipping']['address_2'] ?: $order_data['billing']['address_2'],
     568                'shipping_city' => $order_data['shipping']['city'] ?: $order_data['billing']['city'],
     569                'shipping_state' => $order_data['shipping']['state'] ?: $order_data['billing']['state'],
     570                'shipping_postcode' => $order_data['shipping']['postcode'] ?: $order_data['billing']['postcode'],
     571                'shipping_country' => $order_data['shipping']['country'] ?: $order_data['billing']['country'],
     572                'billing_phone' => $order_data['billing']['phone'],
     573                'billing_email' => $order_data['billing']['email'],
     574                'billing_first_name' => $order_data['billing']['first_name'],
     575                'billing_last_name' => $order_data['billing']['last_name'],
     576                'billing_company' => $order_data['billing']['company'],
     577                'billing_address_1' => $order_data['billing']['address_1'],
     578                'billing_address_2' => $order_data['billing']['address_2'],
     579                'billing_city' => $order_data['billing']['city'],
     580                'billing_state' => $order_data['billing']['state'],
     581                'billing_postcode' => $order_data['billing']['postcode'],
     582                'billing_country' => $order_data['billing']['country'],
     583            );
     584
     585            $address = hippshipp_helper::get_live_rate_param( $meta );
     586
     587            $address = array_map( 'sanitize_text_field', array_filter( $address ) );
     588
     589            $shippment = array(
     590                array(),
     591                $address,
     592            );
     593           
     594            hippshipp_helper::update_order_meta( $order_id, 'shippment', $shippment );
    586595        }
    587596    }
    588597
    589598    function admin_order_metabox() {
    590 
    591599        add_meta_box(
    592600            'shippo-tracking-mtbox',
     
    637645        }
    638646        $opt   = get_option( 'shippo_options' );
    639         $price = absint( $opt['ex_amount'] );
    640 
    641         if ( ! empty( $_SESSION['shippo_shippment'][0][0] ) ) {
    642             $shippment = $_SESSION['shippo_shippment'][0][0]; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    643             $amount_local = isset( $shippment->amount_local ) ? floatval( sanitize_text_field( $shippment->amount_local ) ) : 0;
    644             $amount = isset( $shippment->amount ) ? floatval( sanitize_text_field( $shippment->amount ) ) : 0;
    645             $price += empty( $amount_local ) ? $amount : $amount_local;
    646         }
    647         WC()->cart->total += $price;
     647
     648        if ( isset( $opt['en_shippo'] ) ) {
     649            $price = absint( $opt['ex_amount'] );
     650
     651            if ( ! empty( $_SESSION['shippo_shippment'][0][0] ) ) {
     652                $shippment = $_SESSION['shippo_shippment'][0][0]; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
     653                $amount_local = isset( $shippment->amount_local ) ? floatval( sanitize_text_field( $shippment->amount_local ) ) : 0;
     654                $amount = isset( $shippment->amount ) ? floatval( sanitize_text_field( $shippment->amount ) ) : 0;
     655                $price += empty( $amount_local ) ? $amount : $amount_local;
     656            }
     657
     658            WC()->cart->total += $price;
     659        }
    648660    }
    649661
    650662    function set_checkout_price_total( $posted_data ) {
    651             parse_str( $posted_data, $meta );
    652             $param = hippshipp_helper::get_live_rate_param( $meta );
    653             $rates = hippshipp_helper::get_order_rate( $param );
     663        parse_str( $posted_data, $meta );
     664        $param = hippshipp_helper::get_live_rate_param( $meta );
     665        $rates = hippshipp_helper::get_order_rate( $param );
    654666    }
    655667}
  • hippoo-shippo-integration-for-woocommerce/trunk/readme.txt

    r3360756 r3372485  
    9494
    9595== Changelog ==
     96= 1.1.3 =
     97
     98* Order details bug fix
    9699
    97100= 1.1.2 =
Note: See TracChangeset for help on using the changeset viewer.