id = 'ahcouriers_evening'; $this->instance_id = absint( $instance_id ); $this->method_title = 'AfterHoursCouriers Same Day After Hours Delivery'; // [CHANGE-2026-11-14-6] was "...Evening Delivery" $this->method_description = 'Same Day After Hours Delivery in Melbourne by AfterHoursCouriers. Set up under WooCommerce > AfterHoursCouriers.'; $this->supports = array( 'shipping-zones', 'instance-settings' ); $this->instance_form_fields = array( 'title' => array( 'title' => 'Title', 'type' => 'text', 'default' => 'Same Day After Hours Delivery', // [CHANGE-2026-11-14-6] ), ); $this->title = $this->get_option( 'title', 'Same Day After Hours Delivery' ); // [CHANGE-2026-11-14-6] add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); } public function calculate_shipping( $package = array() ) { $session = function_exists( 'WC' ) && WC()->session ? WC()->session : null; if ( $session ) { $session->set( 'ahcouriers_over_limit', false ); } $dest = AHCouriers_Logic::address_line( $package['destination'] ?? array() ); $from = AHCouriers_Settings::get( 'collection_address' ); if ( '' === $dest || '' === $from || '' === AHCouriers_Settings::get( 'api_key' ) ) { return; } $availability = AHCouriers_API::availability(); if ( ! $availability ) { return; } $slot = AHCouriers_Logic::pick_slot( $availability, AHCouriers_Settings::yes( 'collect_bh' ), AHCouriers_Settings::yes( 'collect_ah' ), AHCouriers_Settings::yes( 'collect_weekends' ) ); // [CHANGE-2026-11-13-4] Shopper's "Deliver from" choice, if valid. $slot = AHCouriers_Logic::choose_time( $slot, (string) ( $package['ahcouriers_deliver_from'] ?? '' ) ); if ( ! $slot || empty( $slot['options'] ) ) { return; } $parcel = AHCouriers_Logic::parcel( self::package_items( $package ), get_option( 'woocommerce_weight_unit', 'kg' ), get_option( 'woocommerce_dimension_unit', 'cm' ), array( 'weightKg' => AHCouriers_Settings::get( 'default_weight_kg' ), 'lengthMm' => AHCouriers_Settings::get( 'default_length_mm' ), 'widthMm' => AHCouriers_Settings::get( 'default_width_mm' ), 'heightMm' => AHCouriers_Settings::get( 'default_height_mm' ), ) ); $tax_enabled = function_exists( 'wc_tax_enabled' ) && wc_tax_enabled(); foreach ( array( 'STANDARD', 'URGENT_2H', 'VITAL_90M' ) as $option ) { if ( ! in_array( $option, $slot['options'], true ) ) { continue; } $q = AHCouriers_API::quote( array( 'collectionAddress' => $from, 'dropoffAddresses' => array( $dest ), 'serviceTier' => AHCouriers_Settings::get( 'service_tier' ), 'deliveryOption' => $option, 'weightKg' => $parcel['weightKg'], 'lengthMm' => $parcel['lengthMm'], 'widthMm' => $parcel['widthMm'], 'heightMm' => $parcel['heightMm'], 'podRequired' => AHCouriers_Settings::yes( 'pod_required' ), 'tollsRequired' => false, 'dangerousGoods' => false, ) ); if ( $q['over_limit'] ) { if ( $session ) { $session->set( 'ahcouriers_over_limit', true ); } return; // same distance for every option } if ( ! $q['ok'] ) { continue; } // [CHANGE-2026-11-13-4] Label shows the "from" time, e.g. // "Evening delivery - Standard (Fri 13 Nov, from 7:00pm)". $label = sprintf( '%s - %s (%s, from %s)', $this->title, AHCouriers_Logic::option_label( $option ), AHCouriers_Logic::short_date( $slot['date'] ), AHCouriers_Logic::time_label( $slot['time'] ) ); $this->add_rate( array( 'id' => $this->get_rate_id( strtolower( $option ) ), 'label' => $label, 'cost' => AHCouriers_Logic::shopper_cost( $q['quote'], $tax_enabled, AHCouriers_Settings::get( 'pricing_mode' ), AHCouriers_Settings::get( 'markup_percent' ) ), 'package' => $package, 'meta_data' => array( // [CHANGE-2026-11-13-4] now includes the "from" time. 'Delivery day' => AHCouriers_Logic::short_date( $slot['date'] ) . ', from ' . AHCouriers_Logic::time_label( $slot['time'] ) . ' (same-day)', '_ahcouriers_option' => $option, '_ahcouriers_date' => $slot['date'], '_ahcouriers_mode' => $slot['mode'], '_ahcouriers_time' => $slot['time'], '_ahcouriers_quote_total' => (string) $q['quote']['total'], ), ) ); } } /** Cart lines -> [weight, length, width, height, qty] in store units. */ public static function package_items( $package ) { $items = array(); foreach ( $package['contents'] ?? array() as $line ) { $p = $line['data'] ?? null; if ( ! $p || ! is_object( $p ) || ( method_exists( $p, 'needs_shipping' ) && ! $p->needs_shipping() ) ) { continue; } $items[] = array( 'weight' => $p->get_weight(), 'length' => $p->get_length(), 'width' => $p->get_width(), 'height' => $p->get_height(), 'qty' => $line['quantity'] ?? 1, ); } return $items; } }