Record additional Product detail in Order upon checkout (Metafield, Cart Attributes or Line Item)

Solved
booter9898
Tourist
7 1 1

I'm trying to work out how I can transfer additional, non Customer defined, Product detail to an Order when a customer makes a purchase.

 

Background
I run a single product business which sells eggs locally. Customers sign up to receive a deliery of eggs either once, or on subscription every 1, 2 or 3 weeks.

 

Customers cannot choose when to receive their delivery. Instead a customer's postcode will determine the day of the week that they receive their delivery.

 

In the first step of the checkout flow, a customer enters their postcode. They are then redirected to the Product page relating to their deliery day (eg Eggs for Thursday delivery).

 

I have created a product for each day of the week (eg Eggs for Monday delivery, Eggs for Tuesday delivery etc).

 

Customers can only buy one product, and they only see the product which delivers to their area. When a new order is created, I need to somehow record the Delivery Day (eg Monday, Tuesday etc) as a discrete value in the order. 

 

What I'm seeking to understand is whether I can achieve this with Metafields, or whether I need to look at alternatives such as Cart Attributes or Line Items.

 

Thank you.

Accepted Solution (1)
booter9898
Tourist
7 1 1

This is an accepted solution.

Ok, this is now resolved. @Made4uo-Ribe your very helpful contribution above got me most of the way there. I also used this very helpful video.

 

The fix (including incorporating the metafield) was to insert the following into the relevant Product Page using a piece of Custom Liquid code:

 

<input type="hidden" name="properties[Delivery day]" value="{{ product.metafields.custom.delivery_day.value }}">

View solution in original post

Replies 5 (5)
Made4uo-Ribe
Shopify Partner
3984 912 1115

Hi @booter9898 

 

I assume that every product page is different for each delivery day? If so, you can pass a product line item in the order. You can read more information here. You can then assign the value base on the product delivery day. You can have this hidden in the customer view, but available at the admin order page. 

Please don't forget to 

Like

 and 

Mark Solution 

to the post that helped you. Thanks!
Sip, savor, and support – your

Coffee Tip

 helps us keep coding magic.❤️❤️❤️
Need a knowledgeable developer? Come and visit us at

Made4uo.com


booter9898
Tourist
7 1 1

Yes, that is correct. Each day of the week has its own product page.

 

Thank you for that suggestion. It sounds as if it might do what I need it to. Are you able to offer any suggestions as to:

 

1) how to prefill/assign the value for that field; and

2) hide that field from customer view?

 

Thanks again.

Made4uo-Ribe
Shopify Partner
3984 912 1115

Hi @booter9898 

 

You can paste the following code to the corresponding products inside the product form. Placement depends on what theme you are using. 

NOTE: You can see the value differs

 

For Monday product:

 

<input type="text" name="properties[_Delivery day]" value="Monday">

 

 

For Tuesday product:

 

<input type="text" name="properties[_Delivery day]" value="Tuesday">

 

 

 

Please don't forget to Like and Mark Solution to the post that helped you. Thanks!

Please don't forget to 

Like

 and 

Mark Solution 

to the post that helped you. Thanks!
Sip, savor, and support – your

Coffee Tip

 helps us keep coding magic.❤️❤️❤️
Need a knowledgeable developer? Come and visit us at

Made4uo.com


booter9898
Tourist
7 1 1

Amazing. Thank you so much. 

 

I have created a Product metafield (product.metafield.custom.delivery_day) and added the Delivery Day for each Product. 

 

If I were to insert the code you provided into the Product page template, rather than 'hard coding' the delivery day for each product, is it possible to populate the line item field with the value of the product.metafield.custom.delivery_day metafield?

booter9898
Tourist
7 1 1

This is an accepted solution.

Ok, this is now resolved. @Made4uo-Ribe your very helpful contribution above got me most of the way there. I also used this very helpful video.

 

The fix (including incorporating the metafield) was to insert the following into the relevant Product Page using a piece of Custom Liquid code:

 

<input type="hidden" name="properties[Delivery day]" value="{{ product.metafields.custom.delivery_day.value }}">