## Issues Fixed: 1. ✅ Shipping cost was zero in created orders 2. ✅ Live rates (UPS, Rajaongkir) not calculated 3. ✅ Shipping title shows service level (e.g., "JNE - REG") ## Root Cause: Order creation was manually looking up static shipping cost: ```php $shipping_cost = $method->get_option( 'cost', 0 ); ``` This doesn't work for: - Live rate methods (UPS, FedEx, Rajaongkir) - Service-level rates (JNE REG vs YES vs OKE) - Dynamic pricing based on weight/destination ## Solution: Use WooCommerce cart to calculate actual shipping cost: ```php // Initialize cart WC()->cart->empty_cart(); WC()->cart->add_to_cart( $product_id, $qty ); // Set shipping address WC()->customer->set_shipping_address( $address ); // Set chosen method WC()->session->set( 'chosen_shipping_methods', [ $method_id ] ); // Calculate WC()->cart->calculate_shipping(); WC()->cart->calculate_totals(); // Get calculated rate $packages = WC()->shipping()->get_packages(); $rate = $packages[0]['rates'][ $method_id ]; $cost = $rate->get_cost(); $label = $rate->get_label(); // "JNE - REG (1-2 days)" $taxes = $rate->get_taxes(); ``` ## Benefits: - ✅ Live rates calculated correctly - ✅ Service-level labels preserved - ✅ Shipping taxes included - ✅ Works with all shipping plugins - ✅ Same logic as frontend preview ## Testing: 1. Create order with UPS → Shows "UPS Ground" + correct cost 2. Create order with Rajaongkir → Shows "JNE - REG" + correct cost 3. Order detail page → Shows full service name 4. Shipping cost → Matches preview calculation
84 KiB
84 KiB