Replacing a Shopify Script with Shopify Functions

We’re trying to replace a Shopify Script with a Shopify Functions app but battling to see how to achieve the same functionality, or even find out if it is possible.

In simple terms the Shopify Script that we have in place currently calculates a shipping rate based on the total cost of the items in the cart excluding products that have a certain tag and after any discounts have been applied to the cart, and it then applies a set shipping rate based on that new total (instead of the actual cart total).

Simple example, if the cart contains:

  • Item A - $100
  • Item B - $100
  • Item C - $100 (tagged to be excluded from shipping calculations)

And there is, let’s say, a 10% discount applied to the order:

  • Initial total: $300
  • Total excluding Item C: $200
  • New total with discount: $180

Now we use $180 as a total to work out which shipping rate should then be applied to the checkout.

Looking into the Shopify Functions API’s it seems that all we are really able to do is manipulate existing shipping rates (rename, reorder or hide etc.) and not actually calculate a new shipping rate.

Does anyone have any insights on this that they wouldn’t mind sharing?

Hi Lester,

I’m not 100% sure I understand your question.

Are you trying to set the numerical value of the shipping rate (for example, $3.50) based on which products are in the cart?

If so, then your best bet is to use a combination of the Shipping Discount Functions API, and the Delivery Customization Functions API.

  • Use a delivery customization to only make certain shipping methods available, based on the contents of the cart.
  • Use a shipping discount to discount the shipping cost to a specific amount. Unfortunately, there’s no way to increase the cost of shipping using a discount, so that might be a challenge.

If you have any questions about this, just reply.

Best,

Tobe