PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 1, 2022

[FIXED] How to create a shopify variable using jQuery datepicker that can then be rendered in email templates?

 July 01, 2022     datepicker, jquery, liquid, onselect, shopify     No comments   

Issue

I am working on my first ecommerce shopify project so I am very new to liquid. I have customised my code to incorporate jQuery's datepicker to select a delivery date and currently when the date is selected and the order is confirmed, the selected date appears in additional information on business side order confirmation, never being visible again to the client. What I would like to do is create a global variable/property that I can: 1. reuse in another liquid page(e.g the confirmation page) and 2: use in an email template. Is this possible and how could I do this?

delivery-date.liquid

  {{ '//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css' | stylesheet_tag }}
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js" defer="defer"></script>

  <div style="width:300px; clear:both;">
    <p>
      <label for="date">Pick a delivery date:</label>
      <input id="date" type="text" name="attributes[date]" value="{{ cart.attributes.date }}" />
    </p>
  </div>

  <script>
    window.onload = function() {
      if (window.jQuery) {
        let $ = window.jQuery;

        $(function() {
          $("#date").datepicker({
            minDate: +1, 
            maxDate: '+2M',
           });
        });
      }
    }
  </script>

then in the cart-template.liquid I render the snippet

{% render 'delivery-date' %}

The email template is able to access properties from the confirmed order like {{ customer.first_name }}, all billing and shipping information etc.


Solution

You can access cart attributes in the email templates (order confirmation or new order) using the attributes array with the same name that you have on the cart page.

<p>Date: {{ attributes["date"] }}</p>

As for the checkout thank you page you can use the the same object {{ checkout.attributes["date"] }} in the Additional scripts section of Shopify Settings > Checkout.



Answered By - cMarius
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing