Why doesn't selected variant change the product photo but other times it does?

Topic summary

A Shopify theme is experiencing intermittent issues where selecting product variants doesn’t update the product photo. The problem occurs inconsistently—sometimes working after a page reload, sometimes not.

Root Cause Identified:

  • JavaScript error in the resetProductFormState function
  • Console shows: Uncaught TypeError: productForm?.toggleSubmitButton is not a function
  • Likely a timing issue where the script runs before productForm is fully initialized

Proposed Solution:

  • Commenting out the problematic function appears to resolve the variant photo switching issue
  • The function’s original purpose was likely to prevent rapid clicking on the “Add to cart” button
  • After removal, the site functions normally, though rapid button clicking behavior may change

Status: The workaround (commenting out the function) seems viable, but the underlying initialization timing issue remains unaddressed.

Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

I can’t figure this out. When I load the page there is a chance that product photos with variants won’t work, then I reload the page and then they work, but customer won’t be reloading the page to see if it works. Sometimes it doesn’t work even after reloading.

Hi, share your URL, please.

https://pawnap.store/products/glow-stitch

there is a problem with the resetProductFormState function in your JS file.

resetProductFormState() {
  const productForm = this.productForm;
  productForm?.toggleSubmitButton(true);
  productForm?.handleErrorMessage();
}

You can see in the console:

Uncaught TypeError: productForm?.toggleSubmitButton is not a function

If the issue disappears after a page reload, it suggests a timing issue - your script might be running before productForm is properly initialized.

What function does it serve? I commented it out and now it seems to be working. Can I live without it?

I think it can prevent fast clicking on the Add to cart button. Try to click it fast 10 times for example. But in general, it works after commented.