WooCommerce Redirect to Checkout After Click on Add to Cart
This woocommerce redirect functionality will force the user to checkout without going to cart page.
When you click on “Add to cart” button then it will automatically redirect you on checkout page and skip the the cart page.
We will cover following steps in this turorial.
1) Disable Ajax Option
2) Change the button text
3) Redirect Hook
4) Remove Success Message
Disable Ajax Option
Go to this path WooCommerce -> Setting -> Product -> General and disable the ajax options
Change the button text
To change the add to cart button text, you need to make filter hook function using “woocommerce_product_single_add_to_cart_text”
function button_text_change( $product ){
return ‘Buy now’;
}
Redirect Hook
Here we will make redirect hook. Means when someone click on add to cart button then it will make redirect to checkout page.
Use this add_filter hook “woocommerce_add_to_cart_redirect” and below function to make redirection on checkout.
function redirect_checkout( $url ) {
return wc_get_checkout_url();
}
Remove Success Message
You will notice that when you will click on Add to cart button and then there will be some success message shown, And you want to get rid of this because we already made redirect functionality to the checkout page.
So, use this add_filter hook “wc_add_to_cart_message_html” using below function to remove the message from cart page
function remove_add_to_cart_success_message( $message ){
return “”;
}
Hope you successfully redirected on checkout page after click on add to cart button.
Original post you can check here
Comments
Post a Comment