Add custom text input field to Shopify Plus checkout

Solved
AesthetiCare
Tourist
5 1 1

We would like to add a custom text input field on the "Information" step of the checkout. We've looked through countless forum threads but can't see an actual answer, so if someone could explain with an example that would be greatly appreciated.

On the "Information" step, just above "Shipping address" we would like a field for Purchase Order Number. Nothing fancy, just the text "Purchase Order Number" and a text input field.

Thanks for your help.

0 Likes

Hello @AesthetiCare ,

Looks like you need to create a cart attribute field in checkout.liquid. As you probably already know, editing this file is only for Plus Stores, and you may have to reach out to Shopify to get access to it if you can't create it in the theme editor.

Here's a pretty good write up on how to create it and what HTML input to put in there.

https://community.shopify.com/c/Shopify-Design/Cart-Use-cart-attributes-to-collect-more-information/...

0 Likes
AesthetiCare
Tourist
5 1 1

We explicitly said in the checkout, not the cart. We've come across that post before and it doesn't seem to help.

0 Likes
AesthetiCare
Tourist
5 1 1

This is an accepted solution.

This code is the solution:

$(document).on(`page:load page:change`, function() {
  if (Shopify.Checkout.step == 'contact_information'){
    
  //create text input variable
  	var input = 
        	'<div class="section section--purchase-order">' +
				'<div class="section__header">' +
      				'<h2 class="section__title">' +
          				'Purchase Order Number'+
      				'</h2>' +
    			'</div>' +

    			'<div class="section__content">' +
    				'<div class="fieldset">' +
    					'<div class="field__input-wrapper"><label class="field__label field__label--visible" for="checkout_purchase_order_number">Purchase Order Number</label>' +
        					'<input placeholder="Purchase Order Number"  autocorrect="off" class="field__input" aria-required="true" size="30" type="text" value="" name="checkout[attributes][purchaseOrderNumber]" id="checkout_purchase_order_number">' +
    					'</div>' +
    				'</div>' +
				'</div>';
                                       
    //append Purchase Order html content
	$(".section--contact-information:first").after(input);
    //listen for changes on the text input
    $("#checkout_purchase_order_number").change(function(){
  		var obj = $("#checkout_purchase_order_number").val();
      //store value in session storage
    	sessionStorage.setItem("purchase_order_number", obj);
	});
    //get the session storage value and display in text input
    var savedObj = sessionStorage.getItem("purchase_order_number");   
    if (savedObj !== null) {        
    $("#checkout_purchase_order_number").val(savedObj);
      
    }
  }
  
});

If you're using jQuery like we are, you need to make sure to include a link to it in checkout.liquid.

0 Likes
apbecerra
Tourist
10 0 5

Hi, 

I am trying to add two new fields in the checkout section of my store.

I saw your answer however I cannot find the checkout.liquid in my code. Would you know where I can find it?

Thanks!

Andrea

0 Likes

Hello @apbecerra ,

Checkout.liquid is usually only available to Shopify Plus plan stores. If you're on Plus, and you still don't see the file, you'll need to contact Shopify and ask them to enable it. Usually just takes a few minutes via their live chat.