Support » Plugin: WooCommerce » Dynamically change variant sku

  • Resolved tobiasheide

    (@tobiasheide)



    I’m using an API that shows a list of refeferal shops. This list is outputted from a javascript, depending on the stores that have the specific SKU in stock. Currently the SKU is included in the script by a small, simple PHP code, outputting the SKU. However, this doesn’t dynamically change when the visitor selects a new variation, which we need.

    I’m not sure how to get the active variant SKU, and how to update it with js/php/ajax.

    Any help is greatly appreciated

    https://imgur.com/a/BVeXp

    data-ean is the one we need to change dynamically

    ` data-displaylanguage=”en”
    data-ean=”<?php echo display_woo_sku(); ?>”
    data-variant-selectiontype=”none”
    data-cookie=”true”
    data-channel=”online”
    data-listtype=”container”
    data-button-text=”køb her”
    data-buy-action-text=”køb her”
    data-containerborder=”false”
    data-local-shopname=”false”`

    • This topic was modified 5 months, 2 weeks ago by  tobiasheide.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Mike

    (@mikedmoore)

    Automattic Happiness Engineer

    Hi there,

    Rather than printing the SKU directly in your data-ean attribute with PHP, you’ll need some JavaScript that is triggered when a new variation is selected. That JavaScript would contact your API(likely via Ajax) and get the new SKU, then print into the data-ean attribute. For an example of what the Ajax call might look like, check this link, and scroll down to the Putting it All Together section

    Plugin Support Andrew

    (@slash1andy)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – but if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.