How to create a custom buy now button in Shopify without the payment gateway. It should be redirected to the checkout page.
{{ form | payment_button }}
above one is a dynamic button. But don’t want to redirect to the payment gateway. It should redirect to checkout.
And I tried the below code. Which is not good. It shows also a popup for add to cart and redirects.
<form action="/cart/add" method="post" class="variants" id="product-actions-{{ product.id }}" enctype="multipart/form-data">
<input type="hidden" name="variantId" value="{{ product.variants[0].id }}" />
<button class="button buynow-btn" title="Buy" onClick="instantBuy()"><span>Buy now</span></button>
</form>
function instantBuy(){
var $ = jQuery;
$(".engo-popup").hide();
var formParams = $('form.cart').serialize();
$.ajax({
url: "/cart/add",
type: "post",
data: formParams,
success: function(){
window.location.href = "/checkout";
},
error: function(){
}
})
}
4
Answers
It was inside the form. That's why it shows a popup
This method adds product to cart & redirects to checkout page.
This method is to create a url link with variant id & total quantity & redirect to checkout Page onclick.
Example:
https://my-shop-name.myshopify.com/cart/36485954240671:3
— checkout with one varianthttps://my-shop-name.myshopify.com/cart/36485954240671:3,31384149360662:1
— Add multiple variant