Shopify Scripts
If your store is on Shopify Plus you can use the Script Editor app from Shopify to create custom Shipping Scripts.
These custom scripts will open up the possibilities of what you can test with ShipScout.
The basic concept is that you can create all the shipping rates in Shopify for all the different variants and then use a Script to detect which variant a visitor is in and hide all the irrelevant rates.
Here is a walkthrough of some of the script logic to get started. To detect which variant a visitor is in:
1
# Set defaults
2
variant = "A"
3
4
# Determine which variant a visitor is in
5
Input.shipping_rates.each do |shipping_rate|
6
if shipping_rate.source === 'ShipScout'
7
variant = shipping_rate.code.include?("fallback") ? "A" : shipping_rate.code.split("_").last #this will set "variant" value to A, B, C etc.
8
end
9
end
Copied!
Then you can add your logic after this. For example, if you set up "Standard Shipping - A" ($5) and "Standard Shipping - B" ($8) rates in Shopify and want to A/B test $5 shipping against $8 shipping you could use this code:
1
Input.shipping_rates.delete_if do |shipping_rate|
2
if variant === 'A'
3
shipping_rate.name === 'Standard Shipping - B' #if in variant A then delete B's rate
4
elsif variant === 'B'
5
shipping_rate.name === 'Standard Shipping - A' #if in variant B then delete A's rate
6
end
7
end
Copied!
You can see how the simple example above could be expanded to test more complex sets of dynamic or weight-based tiered rates that have been set up in Shopify.
Then lastly, since we just used the ShipScout rate as an indicator of which variant the visitor is in and we don't actually want to show that to the customer we can remove the ShipScout rate like this:
1
# Delete the ShipScout rate here since we are only using it as an indicator to show/hide other rates
2
Input.shipping_rates.delete_if do |shipping_rate|
3
shipping_rate.source == 'ShipScout'
4
end
5
6
# Output the rates with these changes
7
Output.shipping_rates = Input.shipping_rates
Copied!
Here's the entire script put together:
1
# Set defaults
2
variant = "A"
3
# Determine which variant a visitor is in
4
Input.shipping_rates.each do |shipping_rate|
5
if shipping_rate.source === 'ShipScout'
6
variant = shipping_rate.code.include?("fallback") ? "A" : shipping_rate.code.split("_").last #this will set "variant" value to A, B, C etc.
7
end
8
end
9
10
# Remove rates not in variant
11
Input.shipping_rates.delete_if do |shipping_rate|
12
if variant === 'A'
13
shipping_rate.name === 'Standard Shipping - B' #if in variant A then delete B's rate
14
elsif variant === 'B'
15
shipping_rate.name === 'Standard Shipping - A' #if in variant B then delete A's rate
16
end
17
end
18
19
# Now rename the rates
20
Input.shipping_rates.each do |shipping_rate|
21
if shipping_rate.name.include? 'Standard Shipping -'
22
shipping_rate.change_name("Standard Shipping")
23
end
24
end
25
26
# Delete the ShipScout rate here since we are only using it as an indicator to show/hide other rates
27
Input.shipping_rates.delete_if do |shipping_rate|
28
shipping_rate.source == 'ShipScout'
29
end
30
# Output the rates with these changes
31
Output.shipping_rates = Input.shipping_rates
Copied!
Note that this example expects 2 shipping rates to be set up in Shopify with the names of "Standard Shipping - B" and "Standard Shipping - A". This is because any shipping rates in Shopify that have identical names will be combined together by Shopify which is not ideal. That is why there is logic in this script to rename the rates (line 19).
Last modified 1mo ago
Copy link