Jump to content

Adding a code into product page

Recommended Posts

Hello, I am trying to add a code into the Additional info block in the product page but once I add the code it does not let me save the product. It tells me there is an unexpected error. Any suggestions? Many thanks! 

Link to comment
  • Replies 3
  • Views 243
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

3 hours ago, Akvile said:

I am trying to add a code into the Additional info block in the product page but once I add the code it does not let me save the product. It tells me there is an unexpected error.

Please provide some more information to allow us to help you.

What is the code you are adding?

How are you adding it?

What is the exact error message? 

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional.

Would you like your customers to be able to mark their favourite products in your Squarespace store?

Link to comment
21 hours ago, paul2009 said:

Please provide some more information to allow us to help you.

What is the code you are adding?

How are you adding it?

What is the exact error message? 

The code looks like this: 

<strong>
    Choose your time zone
</strong>
<div class="tzSelect">
    <div class="form-wrapper">
        <div class="field-list">
            <div class="field">
                <select class="field-element field-timeZone">
                    <option value="Europe/London">Europe/London GMT+0:00</option>    
                    <option value="America/Chicago">America/Chicago GMT-6:00</option>
                    <option value="America/Los_Angeles">America/Los_Angeles GMT-8:00</option>
                    <option value="America/New_York">America/New_York GMT-5:00</option>
                    <option value="CET">CET GMT+1:00</option>
                    <option value="Canada/Atlantic">Canada/Atlantic GMT-4:00</option>
                    <option value="Canada/Central">Canada/Central GMT-6:00</option>
                    <option value="Canada/Eastern">Canada/Eastern GMT-5:00</option>
                    <option value="Canada/Mountain">Canada/Mountain GMT-7:00</option>
                    <option value="EET">EET GMT+2:00</option>
                    <option value="EST">EST GMT-5:00</option>
                    <option value="CST">CST GMT-6:00</option>
                </select>

            </div>
        </div>
    </div>

    <strong>Course starts</strong>
    <div class="timeInTz">
        4/27/2023 3:00:00 PM GMT
    </div>
    <div class="timeInTz">
        4/27/2023 4:30:00 PM GMT
    </div>

</div>

<style>
    .form-wrapper .field-list .field .field-element.field-timeZone {
        margin-bottom: 30px;
    }
</style>
<script>
    var selectTz = document.querySelectorAll('.tzSelect');

    if (selectTz.length > 0) {
        funcTz(selectTz);
    }

    function funcTz(els) {
        for (var index = 0; index < els.length; index++) {
            var element = els[index];
            var tz = element.querySelector('.field-timeZone');
            var txts = element.querySelectorAll('.timeInTz');

            // set inserted date
            tzEls(txts, function (txt) {
                if (!txt.dataset.tz) {
                    txt.dataset.tz = txt.innerText;
                }

                txt.innerHTML = convertTZ(txt.dataset.tz, tz.value);
            });
            

            // on select change
            tz.addEventListener('change', function (e) {
                e.preventDefault();

                var currTz = e.currentTarget.value;

                tzEls(txts, function (txt) {
                    var newDate = convertTZ(txt.dataset.tz, currTz);

                    txt.innerHTML = newDate;
                });
            });

        }
    }

    function tzEls(els, callback) {
        for (var index = 0; index < els.length; index++) {
            var txt = els[index];

            callback(txt);
        }
    }

    function convertTZ(date, tzString) {
        var date = new Date(Date.parse(date)).toUTCString();
        date = new Date(date);
        // 'Europe/London'
        var timeOptions = {
            // weekday: 'long',
            day: 'numeric',
            month: 'long',
            year: 'numeric',
            hour12: true,
            hour: 'numeric',
            minute: '2-digit',
            second: '2-digit',
        };

        if(tzString != null) {
            timeOptions.timeZone = tzString;
        }

        return date.toLocaleString('en-US', timeOptions);
    }

</script>

How are you adding it?

I am going to Edit on the product, then press on Additional info and adding the Code injection block.

What is the exact error message? 

Once I add the code I save it in the additional info and it goes back to Edit page of the product. You can see that I added the code as the Additional info is enabled. Once I press save on the product an error message appears. Please see the picture attached. 

Screenshot 2023-05-24 190009.png

Link to comment

Thanks for the additional information. I don't experience any difficulties adding that code to a Code Block in the Additional Info section of a product, so this seems to be isolated to your site - to which I don't have access.

Although Squarespace won't help you with the code, they should offer assistance if a product isn't saving. It would be worth checking if you experience the same issue when you add a Code Block with the default boilerplate code.

Sorry that I can't be more help.

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional.

Would you like your customers to be able to mark their favourite products in your Squarespace store?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.