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!!
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024