• Resolved sdfbcxvxdsf

    (@sdfbcxvxdsf)


    Would it be possible to set a minimum shipping charger per item + adding distance rate if over certain mileage?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter sdfbcxvxdsf

    (@sdfbcxvxdsf)

    I see the surcharge option, but this does not multiply by number of products

    Thread Starter sdfbcxvxdsf

    (@sdfbcxvxdsf)

    this seems to have done the trick, courtesy of chatgpt:

                // Count total items in the cart
                $total_items = 0;
                foreach ( $package['contents'] as $item_id => $values ) {
                    $total_items += $values['quantity'];
                }
    
                $surcharge = $this->get_rate_field_value( 'surcharge', $rate, '' );
    
                if ( ! strlen( $surcharge ) ) {
                    $surcharge = $this->surcharge;
                }
    
                if ( $surcharge ) {
                    $surcharge_type = $this->get_rate_field_value( 'surcharge_type', $rate, 'inherit' );
    
                    if ( ! $surcharge_type || 'inherit' === $surcharge_type ) {
                        $surcharge_type = $this->surcharge_type;
                    }
    
                    if ( ! $surcharge_type ) {
                        $surcharge_type = 'fixed';
                    }
    
                    if ( 'fixed' === $surcharge_type ) {
                        $cost += $surcharge * $total_items; // Apply surcharge per product
                    } elseif ( 'percent' === $surcharge_type ) {
                        $cost += ( ( $cost * $surcharge ) / 100 );
                    }
                }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Set minimum per item + Distance rate’ is closed to new replies.