To streamline your Free Ship Friday process, you could utilize the Shopify API to develop a tailored script that will autonomously generate the discount on Fridays and eliminate it after a 24-hour period.
Here’s an example in Python that demonstrates how to utilize the Shopify API to automatically set up a Free Ship Friday discount:
import os
import datetime
import shopify
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.getenv('SHOPIFY_API_KEY')
API_PASSWORD = os.getenv('SHOPIFY_API_PASSWORD')
SHOP_NAME = os.getenv('SHOPIFY_SHOP_NAME')
shopify.ShopifyResource.set_user(API_KEY)
shopify.ShopifyResource.set_password(API_PASSWORD)
shopify.ShopifyResource.set_site(f"https://{SHOP_NAME}.myshopify.com/admin")
def create_freeship_friday_discount():
today = datetime.date.today()
if today.weekday() == 4: # Check if today is Friday (weekday() returns 4 for Friday)
# Create price rule
price_rule = shopify.PriceRule.create({
'title': 'Free Ship Friday',
'target_type': 'shipping_line',
'value': '-100',
'value_type': 'percentage',
'allocation_method': 'each',
'starts_at': today.isoformat(),
'ends_at': (today + datetime.timedelta(days=1)).isoformat()
})
# Create discount code using the price rule ID
discount_code = shopify.DiscountCode.create({
'price_rule_id': price_rule.id,
'code': 'FREESHIPFRIDAY'
})
if __name__ == "__main__":
create_freeship_friday_discount()