Hello, when creating an order, I need to calculate the shipping price according to my logic, through my api, how can I do this?
Checkout Carrier Calculated Shipping (CCS) in Shopify
https://shopify.dev/docs/api/admin-rest/2023-01/resources/carrierservice
# Shipping lines format
shipping_lines = [{
title: your_shipping_title,
price: your_shipping_line_price,
code: your_shipping_code,
source: your_shipping_line_source
}]
# Example
shipping_lines = [{
title: "Standard Shipping",
price: 10.0, # if you want free shipping, you can set this as 0
code: "Standard Shipping",
source: "shopify"
}]
# Create order using Shopify API
payload = {
# other fields
shipping_lines: shipping_lines
}
ShopifyAPI::Order.create(payload)
That is, I create an endpoint (I accept it), I process everything and give the response, will this be taken into account when ordering an order and during checkout?
Yes. Exactly.
Be mindful that you need CCS to be enabled on your store for this to work.
Check this document on how you can get CCS activated: https://help.shopify.com/en/manual/shipping/setting-up-and-managing-your-shipping/enabling-shipping-carriers