Finding the callback functions on Broadcast theme (2.0)

Finding the callback functions on Broadcast theme (2.0)

Davethebrave
Tourist
4 0 1

Hi All,

 

Im trying to add certain fields to the product page like SKU.

i have managed to add the fields to the page but they do not update upon selecting the variants.

i cant find the callback functions in the theme code of broadcast - the thing that makes the price and images update as you select a variant.

 

Can someone guide me on this please?

Replies 3 (3)

AliReviews
Shopify Partner
773 90 358

Hello @Davethebrave ,

 

You can try to follow these steps:

  • Go to Online Store -> Themes -> Actions -> Edit code 
  • Go to Sections folder -> find the product-template.liquid file or something name similar to it
  • Search for the HTML code that generates the variant select element. It might look like a <select> or <input> element with the name="id" attribute.
  • Identify the callback functions: Once you've found the variant select element, search for the JavaScript code that handles variant selection and updates the product information dynamically. Look for functions that are triggered when a variant is selected or changed. Common names for these functions include updateVariant, selectCallback, or onVariantChange.
  • Add your field update code: Within the variant callback function(s), you'll need to add code to update the SKU field based on the selected variant. The exact code will depend on the structure of your theme and how the SKU is stored. Here's a basic example of how you can update the SKU field using jQuery:
// Example code to update the SKU field
function updateSku(variant) {
  var skuElement = $('.product-sku'); // Replace with the selector for your SKU element
  skuElement.text(variant.sku);
}

// Example callback function that gets triggered on variant change
function onVariantChange(variant) {
  // Call your existing code that updates the price and images here

  // Update the SKU field
  updateSku(variant);
}
  • Save changes

Hope this can help.

Ali Reviews team.

- Was my answer helpful? Please hit Like or Mark it as solution!
- Ali Reviews - The must-have Shopify app that empowers you to effortlessly collect, display, and manage product reviews.
- Start your FREE trial today!
Davethebrave
Tourist
4 0 1

Hi ALi,

 

thanks for that - but i cant find any of those terms in the files of BROADCAST

 

see picture attached - relevant?Screenshot 2023-05-21 at 11.13.00 PM.png

wasimaliawan
Shopify Partner
7 2 0

Its too late but here is the call back function for broadcast theme that handles the product information update on variant change event. 

wasimaliawan_0-1736276101944.png