No announcement yet.

Where to put custom scripts

  • Filter
  • Time
  • Show
Clear All
new posts

  • Where to put custom scripts

    I have a minor UI script we need on the checkout page, we have a custom One Page Checkout (OPC).
    Specifically when a specific shipping method is available, the script should append to the label text a link that opens a modal window with more details about the option.
    I have a little jQuery and some content section data that when I run the script from the browser console works exactly as I want.
    I cannot find where to put this script so that it runs reliably in the OPC.
    I have tried:
    • putting the script snippet in a JavaScript Resource and tying that to the OPC page
    • putting the script in the OPC header
    • putting the script in the OPC footer
    • putting the script in the global footer
    I’m uncertain what to try next.

    Here is a pastebin of the script snippet --

    Look below to see the solution in a set of little posts
    Last edited by cpp-dev; 06-25-20, 08:24 AM.

  • Technically, if that script is after the call to jQuery before the closing BODY tag, it should work. However, since this is for a custom one page checkout, there may be JavaScript code with that customization which is making it so your code never fires. You may need to check the custom code or contact the developer.
    Matt Zimmermann
    Director of UI/UX
    / Miva, Inc.


    • Does your modal window container for the selected shipping option already exist on the page?

      What help do you need today!
      Interactive Design Solutions
      MivaMerchant Business Partner | Certified MivaMerchant Web Developer
      My T-shirt Collection is mostly MivaCon T-shirts!!
      Competitive Rates, Popular Modules, and Integrations:
      Product Copy | AutoBaskets | Waitlist Integration| Wholesale Integration


      • I got a solution, with the help of the MAP team and it touched more templates than I was expecting.

        The leading issue that came out of it was that my little jQuery snippet was being clobbered by
        The forum editor doesn't seem to like the length of my original post so I'm going to section it up an hopefully it's still readable.


        • Thanks for your input ids

          - One Page Checkout content section (because custom needs)
          <div class="form-row shipping-method-row">
            <span class="column one-tenth"><input type="radio" name="ShippingMethod" value="&mvte:method:module;:&mvte:method:code;" &mvt:method:checked; id="l-shipping-method-&mvte:shippingMethodCode;" class="shipping-method-radio" data-price="&mvt:method:price;"></span>
            <label for="l-shipping-method-&mvte:shippingMethodCode;" class="column three-fifths">&mvt:method:name;<mvt:if expr="'Same-Day Local Delivery' CIN l.settings:method:code"> <a href='#same-day-shipping' id='same-day-details'>(More Info)</a></mvt:if></label>
            <mvt:if expr="NOT ISNULL l.settings:method:price">
              <span class="column three-tenths align-right shipping-method-price-formatted">&mvt:method:formatted_price;</span>
          - This puts the label in specifically and adds the link like I had intended


          • - Global Footer -- I had to put the script tags in the [] because the editor was blocking the posting (I think this was what was making it unhappy before too)
            <mvt:elseif expr="g.Screen EQ 'OPC'">
                    $(document).ready(function() {
                        $(document).on('click', '#same-day-details', function(q) {
                                items: {
                                    src: '#js-same-day-shipping-wrapper',
                                    type: 'inline'
            - as you can see this does the popup handling
            Last edited by cpp-dev; 06-25-20, 08:23 AM. Reason: stylistic addition of [] so I could post it


            • - OPC page Footer
                  <div id="js-same-day-shipping-wrapper" class="mfp-hide white-popup">
                      <mvt:item name="readytheme" param="contentsection( 'same-day-shipping' )" />
              - This is the content section that is loaded when the popup called.

              What do we draw from this? Well, the solution isn't, "just add JavaScript"™. While a simple JS solution would be kinda cool, it's not always ideal, and this highlights the capabilities of the MVT system and hopefully shows some folks how they can effectively affect their pages.



              This website uses cookies to identify visitors, track visitors to our website, store login session information and to remember your user preferences. By continuing to use this site you agree to our use of cookies. Learn More.

              This website uses cookies. By continuing to use this site you agree to our use of cookies. Learn More.