Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Solved! Go to the solution
This is an accepted solution.
Hi @timmycodes88,
Please go to product-template.liquid file, find 'payment_button' and change code here:
Code:
<button type="button" class="btn product-form__cart-submit btn--secondary-accent" data-buy-now>
<span>
Buy now
</span>
</button>
<script>
document.querySelector('[data-buy-now]').addEventListener('click', () => {
let addToCartForm = document.querySelector('form[action$="/cart/add"]');
let formData = new FormData(addToCartForm);
fetch(window.Shopify.routes.root + 'cart/add.js', {
method: 'POST',
body: formData
})
.then(response => {
window.location.href = '/checkout';
return response.json();
})
.catch((error) => {
console.error('Error:', error);
});
});
</script>
Hope it helps!
Hi @timmycodes88,
You cannot edit the code at '{{ form | payment_button }}', the code is rendered automatically according to your payment settings.
So you can just change the payment settings, let it support only PayPal, or customize the button to go straight to the checkout page like your suggestion.
Hope it is clear to you.
Hi @timmycodes88,
You can totally add code to show buy now. What theme are you using? Please send me the theme name, I will help you check it.
Yes simply Debut!
Thank you Lit!!
This is an accepted solution.
Hi @timmycodes88,
Please go to product-template.liquid file, find 'payment_button' and change code here:
Code:
<button type="button" class="btn product-form__cart-submit btn--secondary-accent" data-buy-now>
<span>
Buy now
</span>
</button>
<script>
document.querySelector('[data-buy-now]').addEventListener('click', () => {
let addToCartForm = document.querySelector('form[action$="/cart/add"]');
let formData = new FormData(addToCartForm);
fetch(window.Shopify.routes.root + 'cart/add.js', {
method: 'POST',
body: formData
})
.then(response => {
window.location.href = '/checkout';
return response.json();
})
.catch((error) => {
console.error('Error:', error);
});
});
</script>
Hope it helps!
So grateful, I was able to implement exactly what I wanted!!
Thank you LitExtension!!
We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024We want to take a moment to celebrate the incredible ways you all engage with the Shopi...
By JasonH Oct 15, 2024