Home Forums WoodMart support forum Custom JS for Product Variations

Custom JS for Product Variations

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #421676

    WASIPLtd_Website
    Participant

    Hello,

    I’m using custom JS to update my site’s URL based on the product variation a customer selects. It only updates the link when a change is made using the dropdown options. I am using colour swatches to change the product color variation but the link does not update when changed. How can I update my URL when a colour swatch is selected?

    Checking the logs, I see that ‘els’ contains both the colour and size of the product. However, when I check ‘el’ inside the forEach loop, only the size is passed on.

    JS:
    const els = document.querySelectorAll(‘.variations select’)

    // add el.name and el.value as query parameters to the URL
    function updateURL(el) {
    const url = new URL(window.location.href)
    url.searchParams.set(el.name, el.value)
    window.history.pushState({}, ”, url.href)
    }

    // update the URL when the user changes the select
    els.forEach(el => el.addEventListener(‘change’, () => updateURL(el)))

    Attachments:
    You must be logged in to view attached files.
    #421760

    Luke Nielsen
    Keymaster

    Hello,

    Unfortunately, such customization is not included in our support.

    You can get acquainted with Envato Support Policy here:

    https://themeforest.net/page/item_support_policy

    I do hope you would remain as our valued customer and thank you for your time.

    Kind Regards

Viewing 2 posts - 1 through 2 (of 2 total)