I am developing a project in Shopify with Brooklyn Theme for a client. Our client has only three products to show with 4 variants for each product. As per the requirement, we don't have to redirect on Cart page just have to redirect to the Checkout Page on clicking a button on the product page after adding the variant.
For this, I have googled to find the right solution but couldn't have a right solution for that. So I coded the process in jquery and it is working. But the process which I did is a nasty way and I want some clean process . I know there is an app but my client does not intend to purchase any app for it.
What I scripted is:
In the product-template.liquid the file I have commented out the Add to Cart button and instead, I added a button.
<button name="checkoutty" class="btn to">Checkout</button>
And a script in that liquid template:
$(function() {
$(window).on('load',function(){
$.ajax({
type: "POST",
url: '/cart/clear.js',
success: function(){
//alert('I cleared the cart!');
},
dataType: 'json'
});
})
});
$(document).ready(function(){
$('.single-option-selector__radio').click(function(){
if($(this).is(':checked')){
$('.product-single__add-to-cart button[type="submit"]').removeClass('disabled').attr('disabled','');
$('button[type="submit"]').attr('disabled','');
}
});
$('.to').click(function(){
$('[action="/cart/add"]').trigger('submit')
});
});
And in the cart.liquid template
<script>
$(window).load(function(){
$('.cart__checkout').trigger('click');
});
</script>
Though it is working I am not happy with this as it is redirecting to the cart page and then to checkout page as I have forced the cart add form to submit and then Checkout btn click event on the cart liquid page`.
On the Cart Page I may have additional preloader to hide the content. So all these are the nasty process. Can anyone please guide me for any simpler and clean process.
Thanks in advance.