Shipping, add $1.00 for each additional item in the cart

Hello! I have a general inquiry, quick fix, etc.

I have a client that wishes to add $1.00 to the total shipping for every additional item in the cart. If flat rate shipping is $5.00, and someone adds 3 items to the cart, the new shipping total should be $7.00.

Is this possible? Is there a simple solution we can install for this? We are comfortable editing code to place in whatever you need. Let us know.

Thanks!

  • Vaughan

    Hi Brandon,

    Hope you're well?

    Yes, this should be possible with a bit of custom code :slight_smile:

    There's a filter we could probably use for thi, so we wouldn't need to actually edit the plugin code at all.

    apply_filters( 'mp_calculate_shipping_' . mp_get_setting( 'shipping->method' ), 0, $total, $cart, $address1, $address2, $city, $state, $zip, $country, $selected_option );

    So we can change the price on this for flat rate by creating a filter and function.

    add_filter( 'mp_calculate_shipping_flat_rate', 'wpmudev_mp_additional_item_ship_charge', 99, 10);
    function wpmudev_mp_additional_item_ship_charge($price, $total, $cart, $address1, $address2, $city, $state, $zip, $country, $selected_option ) {
    // code here
    
        return (float) $price;
    }

    Leave it with me for a bit & i'll write up some code to achieve this for you. Will need to check a few things and run some tests first.

    Hope this helps

  • Vaughan

    Hi Brandon,

    It happened to be a bit more difficult than expected. I did need to make a change in the marketpress plugin core unfortunately.

    Please find the attached zip

    Inside the zip you will find 2 files;

    Copy mp-flat-rate.php to the following location (overwriting the existing file)

    /wp-content/plugins/marketpress/includes/common/shipping-modules/mp-flat-rate.php

    Copy the file: mp_custom_shipping_functions.php

    to the following location:

    /wp-content/mu-plugins/

    That should then give you an additional $1 shipping charge for every additional item in the cart.

    so if your flat rate is $5

    You have 5 items in cart.

    The shipping charge will now be $5 + 4 = $9

    Don't worry about the marketpress edit being overwritten on the next update, we will make sure this change gets added to the core :slight_smile:

    Additionally, if you wish to change the value of the additional charge, open up the /wp-content/mu-plugins/mp_custom_shipping_functions.php

    and change the value in $additional_item_price

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.