Wpd Ai Order Shipping Cost Default Value

Alpha Insights Documentation

Docs Navigation



Filter: wpd_ai_order_shipping_cost_default_value

Filter the default shipping cost calculated for an order before using saved meta values.

Description

Allows dynamic shipping cost calculation based on order details, shipping method, destination, or integration with shipping carriers/fulfillment services.

Location

File:includes/classes/WPD_Order_Calculator.php

Method:WPD_Order_Calculator::get_shipping_cost()

Line:~488

Parameters

Parameter Type Description
$shipping_cost float Calculated shipping cost (default calculation)
$order WC_Order WooCommerce order object

Return

Type: float

Description: Modified shipping cost

Example Usage

Flat Rate by Shipping Method

add_filter( 'wpd_ai_order_shipping_cost_default_value', 'custom_shipping_cost', 10, 2 );

function custom_shipping_cost( $shipping_cost, $order ) {
    $shipping_methods = $order->get_shipping_methods();
    
    foreach ( $shipping_methods as $method ) {
        $method_id = $method->get_method_id();
        
        // Set actual costs by shipping method
        switch ( $method_id ) {
            case 'flat_rate':
                return 5.50;
            case 'free_shipping':
                return 6.00; // Your actual cost for "free" shipping
            case 'local_pickup':
                return 0.00;
            default:
                return $shipping_cost;
        }
    }
    
    return $shipping_cost;
}

Integration with ShipStation

add_filter( 'wpd_ai_order_shipping_cost_default_value', 'shipstation_actual_cost', 10, 2 );

function shipstation_actual_cost( $shipping_cost, $order ) {
    // Get actual shipping cost from ShipStation
    $shipstation_data = get_post_meta( $order->get_id(), '_shipstation_shipping_cost', true );
    
    if ( $shipstation_data && is_numeric( $shipstation_data ) ) {
        return (float) $shipstation_data;
    }
    
    // Fallback to default calculation
    return $shipping_cost;
}

International Shipping Premium

add_filter( 'wpd_ai_order_shipping_cost_default_value', 'international_shipping_cost', 10, 2 );

function international_shipping_cost( $shipping_cost, $order ) {
    $country = $order->get_shipping_country();
    
    // Higher costs for international
    if ( $country !== 'US' ) {
        $shipping_cost += 12.00; // Add international handling
    }
    
    return $shipping_cost;
}

Weight-Based Calculation

add_filter( 'wpd_ai_order_shipping_cost_default_value', 'weight_based_shipping', 10, 2 );

function weight_based_shipping( $shipping_cost, $order ) {
    $total_weight = 0;
    
    // Calculate total order weight
    foreach ( $order->get_items() as $item ) {
        $product = $item->get_product();
        if ( $product ) {
            $weight = $product->get_weight();
            $quantity = $item->get_quantity();
            $total_weight += (float) $weight * $quantity;
        }
    }
    
    // $0.50 per lb
    $calculated_cost = $total_weight * 0.50;
    
    // Minimum $5 shipping
    return max( $calculated_cost, 5.00 );
}

Important Notes

  • Saved order meta overrides this filter (manual entry takes precedence)
  • Return float value in store’s base currency
  • This is the DEFAULT value – users can still manually override per order

Related Filters

Got A Question?

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Alpha Insights

Alpha Insights

The World's Most Advanced WooCommerce Drag & Drop Report Builder.

5/5 – Trustpilot

Alpha Insights