• Resolved waxinggibbous

    (@waxinggibbous)


    Since the plugin doesn’t take into account the size of the actual shipping box (when calculating by weight), is there a way to automatically add an upcharge (either percent or fixed amount) to the displayed shipping rate? In testing orders, I’ve found that the postage rate being pulled is sometimes several dollars lower that the actual rate charged by USPS – particularly when an order includes multiple items that require a larger box.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Dan

    (@dangoodman)

    Hello @waxinggibbous,

    Adding the following code snippet to your theme’s functions.php will increase the shipping costs by the predefined percentage:

    add_filter('woocommerce_package_rates', function ($rates) {
    
        $percentage_increase = 0.10; // 10% increase. Change this to your desired percentage (e.g., 0.15 for 15%).
    
        foreach ($rates as $rate_id => $rate) {
            $original_cost = $rate->cost;
            $new_cost = $original_cost + ($original_cost * $percentage_increase);
            $rate->cost = $new_cost;
    
            // Increase the cost of shipping taxes as well if applicable
            if (!empty($rate->taxes)) {
                foreach ($rate->taxes as $tax_id => $tax) {
                    $rate->taxes[$tax_id] = $tax + ($tax * $percentage_increase);
                }
            }
        }
    
        return $rates;
    });
    Thread Starter waxinggibbous

    (@waxinggibbous)

    Worked perfectly! Thanks for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.