Hi @Dimtar
Creating a custom Shopify app to add custom shipping methods and rates at checkout is definitely achievable, but it involves understanding Shopify’s architecture and some of its limitations. Here’s a step-by-step guide:
1. Understand Shopify’s Limitations- Checkout Restrictions: For Shopify Plus merchants, the checkout process can be customized using the Checkout Scripts API. If you’re not on Shopify Plus, the checkout cannot be directly modified.
- Third-Party Apps: If you’re on a standard Shopify plan, you’ll need to rely on custom apps that calculate shipping rates using the Carrier Service API.
2. Approach to Develop the Custom App#### A. Enable Carrier-Calculated Shipping- This feature is required to display custom shipping rates during checkout.
- Contact Shopify Support to enable this feature if it’s not already available on your plan (it’s included for Plus merchants or available as an add-on for others).
B. Use the Carrier Service API- The Carrier Service API allows you to create custom shipping methods and rates dynamically.
- The API responds with shipping rates based on the cart’s content, weight, shipping address, and other parameters.
Key Steps to Implement:
1-Set Up a Shopify Custom App:
- Go to Shopify Admin > Apps > Develop Apps.
- Create a new custom app and install it on your store.
2-Register a Carrier Service:
- Use the CarrierService object to register your service.
Example API endpoint for registering:
POST /admin/api/2023-01/carrier_services.json
{
“carrier_service”: {
“name”: “Custom Shipping”,
“callback_url”: “https://your-server.com/custom-shipping”,
“service_discovery”: true
}
}
3-Set Up Your Callback Endpoint:
- Your app’s server will receive a POST request when Shopify needs to fetch shipping rates.
Example callback response:
{
“rates”: [
{
“service_name”: “Express Delivery”,
“service_code”: “EXPRESS”,
“total_price”: 1000, // Price in cents
“currency”: “USD”,
“min_delivery_date”: “2025-01-21T14:00:00Z”,
“max_delivery_date”: “2025-01-23T14:00:00Z”
},
{
“service_name”: “Standard Delivery”,
“service_code”: “STANDARD”,
“total_price”: 500,
“currency”: “USD”,
“min_delivery_date”: “2025-01-24T14:00:00Z”,
“max_delivery_date”: “2025-01-28T14:00:00Z”
}
]
}
4-Host the App:
- Use a reliable hosting service like AWS, Google Cloud, or Heroku.
- Ensure your server uses HTTPS (Shopify requires secure endpoints).
C. Test the Integration- Add test orders to ensure the shipping methods appear correctly at checkout.
- Verify that rates are calculated as expected based on inputs like weight or destination.
3. Consider Using Webhooks- Use Shopify webhooks to track changes in orders or shipping configurations.
- Example webhook topics: orders/create, orders/fulfilled.
4. Customize Shipping Labels (Optional)- If you need label printing, integrate with third-party APIs like Shippo or EasyPost for label generation.
5. Shopify Plus (Advanced Customization)- If you’re on Shopify Plus, you can create advanced checkout customizations using Shopify Scripts.
- Example: Offer discounts or modify shipping rates based on customer tags or order value.
Example Code for the Callback Server (Node.js)
Here’s a basic server setup for handling rate requests:
const express = require(‘express’);
const app = express();
const PORT = 3000;
app.use(express.json());
app.post(‘/custom-shipping’, (req, res) => {
const shippingRates = {
rates: [
{
service_name: “Express Delivery”,
service_code: “EXPRESS”,
total_price: 1500, // in cents
currency: “USD”,
min_delivery_date: “2025-01-21T10:00:00Z”,
max_delivery_date: “2025-01-23T10:00:00Z”
},
{
service_name: “Standard Delivery”,
service_code: “STANDARD”,
total_price: 800,
currency: “USD”,
min_delivery_date: “2025-01-24T10:00:00Z”,
max_delivery_date: “2025-01-28T10:00:00Z”
}
]
};
res.json(shippingRates);
});
app.listen(PORT, () => {
console.log(Server is running on port ${PORT});
});
Final Notes
If you’re on a plan without checkout customization options, you may need to explore alternatives like upgrading to Shopify Plus or using apps from the Shopify App Store that offer similar functionality.
If you need any other assistance, feel free to reply and I will try my best to respond.
Best regards,
Daisy