Repository navigation
Shopify custom product form sends the wrong ID? Check the variant input #41
vistabylara-dev
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
إضافة منتج إلى السلة تحتاج معرّف المتغير، وليس معرّف المنتج الأساسي.
Free Shopify code series · 38/50 · Reviewed 24 October 2026
The problem
A custom product form can submit a product ID where a variant ID is required. This fragment shows the initial hidden variant field for an already-existing product form.
Placement and precautions
Duplicate the theme and work in its unpublished preview. Save the original files and change one component at a time.
Use only inside the existing Shopify product form and only where its variant-ID input belongs. Replace the wrong input; do not add a second name=id field. Preserve the form's existing variant selector and update logic.
Bounded Liquid example — not a replacement for an entire theme file:
{% assign form_variant = product.selected_or_first_available_variant %} {% if form_variant != blank %} <input type="hidden" name="id" value="{{ form_variant.id }}"> {% endif %}Check in preview
Inspect submitted form data in a development store. Confirm id matches the chosen variant after initial load and after changing options. Check sold-out choices, required selling plans and quantity rules.
Limits to understand
The hidden field is initial-render only. It does not update itself or validate availability, and is not a complete product form. Never use it to bypass the theme's inventory or subscription controls.
Validation: This code passed Shopify's validation tool. This is static validation, not proof of rendering, accessibility, theme compatibility, indexing or improved sales. No live merchant store was changed or purchase performed.
Rollback
Restore the saved markup and styles if anything regresses. Remove any new calls before deleting their referenced files. Remove only unused locale keys introduced for this example. Keep the previous working theme available until the full affected journey has been checked.
Need this fixed in your store?
Send Dr Lara your store URL, theme name, affected page and what changed before the issue started. Start with free guidance and a free initial consultation. If you want implementation, we agree the scope and fee separately before work starts.
Explore Shopify repairs and development with Vista by Lara
WhatsApp Dr Lara about guide 38 or call +971 50 799 4292.
Free guidance. No commitment. Practical implementation is separately scoped.
Join the discussion
What result do you see, and what should happen instead? Share a short sanitized example. Remove passwords, tokens, customer details and private admin URLs.
Official references
Dr Lara · Vista by Lara · Dubai, UAE
All reactions