Ecommerce Shopify WordPress Discussion

The custom "Buy Now" button in shopify is not working correctly

How to create a custom "Buy Now" button in Shopify so that it goes to the checkout page and not to cart. The problem is that when the user for the first time goes to the site clicks the button, he is redirected to the main page of the site and not to the checkout page. When the button is pressed again, everything works. enter image description here My code {% form 'product', product %} <div class="item-bottom"> <div class="item-left"> <h4>quantity</h4> <div class="item-count"> <div class="button-container"> <button type="button" id="decrease">-</button> </div> <input type="text" name="quantity" min="1" value="1" id="quantity" aria-label="Quantity of goods"> <div class="button-container"> <button type="button" id="increase">+</button> </div> </div> </div> </div> <div class="item-price"> <h4>price</h4> <p>{{ product.price | money }} <span>129.99$</span></p> </div> <select name="id" style="display: none;"> <option value="{{ product.variants[0].id }}"> {{ product.variants[0].title }} </option> </select> <button class="button buynow-btn" title="Buy" onClick="instantBuy()">Buy now</button> {% endform %} function instantBuy(){ var $ = jQuery; var formParams = $('form').serialize(); $.ajax({ url: "/cart", type: "post", data: formParams, success: function(){ window.location.href = "/checkout"; }, error: function(){ } }) }
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.