I would like to check the amount of a shipping rate and see what it ends with, so I can then discount a set amount.
Basically I want to be able to do modulo math. Like
if shipping_rate.price.cents % 100 == 95
# discount specific amount
But I can’t find any way to get a range of digits from a Money object in Shopify Scripts. And I don’t see how to convert a Money object to an integer.
My use case: we have a bunch of shipping rates for differing amounts, some from apps using carrier calculated rates, some from Shopify shipping profiles. We want to discount only the amount of the Shopify provided rates, not the app provided rates.
The problem is when rates are merged (“source: Shopify”). I can detect when merged, but I can’t discount just the app provided rates.
There’s a bunch of different instances where we may or may not want to apply a discount, primarily cart thresholds. I can figure it out using some simple modulo math due to how are rates are set up — but I can’t figure out how to access those final two digits within a Shopify Script.
How do I convert a Money object to an integer or compare to just certain digits in a money object?