2 shipping scripts - How can I combine them?

mickhb
Visitor
2 0 0

I have two scripts for the checkout.

How can I combine them? Only one script can be published in the checkout section in the script editor. 

 

The first script for sorting the shipping solution

desired_order = ["DHL","FedEx","DPD","FedEx Express","DPD Express"]

Output.shipping_rates = Input.shipping_rates.sort_by do |shipping_rate|
desired_order.index(shipping_rate.name) || desired_order.length
end

and a second script to hide the shipping solution when entering a Packstation in the address field.

shippingaddress1 = Input.cart.shipping_address.address1.upcase.split[0...-1].join ' '
checkpobox = ['PACKSTATION','POSTFILIALE','PACK','POST']
puts shippingaddress1
if checkpobox.include?(shippingaddress1)
  hideship = ['DPD','DPD Express','FedEx','FedEx Express']
else
  hideship = ['NO DPD']
end

Output.shipping_rates = Input.shipping_rates.delete_if do |shipping_rate|
  hideship.any? { |hideship| shipping_rate.name.include?(hideship) }
end

Thanks for help

Replies 2 (2)

mickhb
Visitor
2 0 0

Could anyone help?

Is it also possible to include a query that if "checkpobox" has something entered like 'PACKSTATION','POSTFILIALE' , then the field "Optional address2 label" is a required field?

 

Thanks a lot

joshkirk
Tourist
3 0 3

I had the same question, but then used this tool to create the 2 things that I needed to do: https://jgodson.github.io/shopify-script-creator/

Not 100% sure it will work specific to what you need...