Hey there, I’m doing some custom logic on order/created webhook to give rewards to customers.
I’m developing a feature where, when storefront is access with a specific URL parameter, I’ll override my default logic to something else.
For example:
Default program => 10% off order
UTM parameter (mystore(.)com/?rdm_campaign=20OFF) => 20% off order
I initially planned to use store that UTM parameter in cart attributes so I can apply my custom campaign on order/created BUT I’ve noticed that cart attributes doesn’t apply when using Dynamic Checkout Buttons.
I also thought about Web Pixel but I’m afraid of 1° race condition with the order/created webhook and 2° I think customers can turn off completely pixel tracking.
Is there any solutions to handle that use case? Any workaround for cart attributes & Dynamic buttons?
Have you looked at potentially using cart based metafields to add a custom metafield to a cart and then applying custom logic for a discount based on these conditions?
I always hesitated using cart notes for UUIDs because they pollute the order details UI, and merchants could directly edit them in the order details page as well.
Do cart metafields automatically convert to order metafields during post-purchase like in Checkout Extensions?
Never looked at it but I can think of some issues with Storefront API cartCreate:
1° If I create a new cart with this method then does the newly created cart is somehow automatically bound to the customer’s session? (when he adds/deletes product to his cart for example)
2° Looks like Dynamic Checkout Buttons also using cartCreate as shown in the screenshot, I may face the same issue as previously where a totally new cart is created, so no metafields inside
3° Great question from @Dylan: does cart metafield gets automatically converted to order metafield so I will be able to retrieve them in order/created webhooks?
Hi again - from looking into this more, I’m not sure cart metafields will be the most practical solution for this usecase, as they won’t automatically convert to order metafields during the post-purchase process (like with Checkout Extensions).
If you need to transfer cart metafields to order metafields, you’ll need to implement a custom solution, like Shopify Flow or a custom app, to handle the transfer of data from the cart to the order after the purchase is completed.
I dont really think you have many options for a good solution. I’ve used cart attributes myself - however, mostly to add the URL param scope to liquid to avoid unnecessary javascript.
Do you rely a lot on the dynamic buttons, or can you disable them (maybe just in the cases where this is relevant)? I didn’t know that they dont pass attributes - sounds weird.
Do they pass line props, so you potentially could hack through it by changing cart attributes to line props when creating the checkout?
Hi, yaman
I’m wondering if the function of automatically applying a discount code works for you. What I mean is, when your customers access a specific URL parameter, add items to the cart, and then a 20% off discount code is fetched and applied automatically.