WooCommerce Setting Disable AJAX add to cart buttons
Go to WooCommerce > Settings on your WooCommerce Admin Dashboard. Next, under the Products tab, click General settings and Uncheck the “Redirect to the cart page after successful insertion” option. Uncheck the “Allow AJAX add to cart buttons on archives” checkbox, then save your adjustments.
Change the Add to Cart Button Text
<?php
/*
* Change Add to Cart button text on Product Archives Page
*/
add_filter( 'woocommerce_loop_add_to_cart_link', 'cxc_add_to_cart_archive_change_text' );
function cxc_add_to_cart_archive_change_text( $add_to_cart_html ) {
return str_replace( 'Add to cart', 'Buy now', $add_to_cart_html );
}
/*
* Alternative Solutions
*/
add_filter( 'woocommerce_product_add_to_cart_text', 'cxc_add_to_cart_archive_change_text_1', 10, 2 );
function cxc_add_to_cart_archive_change_text_1( $text, $product ){
return $product->is_purchasable() && $product->is_in_stock() ? 'Buy Now' : 'Read more';
}
?>
<?php
/*
* Change Add to Cart button text on Product Pages
*/
add_filter( 'woocommerce_product_single_add_to_cart_text', 'cxc_add_to_cart_product_change_text' );
function cxc_add_to_cart_product_change_text( $product ){
return 'Buy now';
}
?>
After Adding a Product to Cart, Redirect to Checkout
<?php
/*
* Redirect To Checkout Page
*/
add_filter( 'woocommerce_add_to_cart_redirect', 'cxc_add_to_cart_redirect_checkout_page' );
function cxc_add_to_cart_redirect_checkout_page( $url ) {
return wc_get_checkout_url();
}
?>
Remove the Added to Cart Message “The product has been added to your cart”
<?php
/*
* Remove the Added to Cart Message
*/
add_filter( 'wc_add_to_cart_message_html', 'cxc_remove_add_to_cart_message_checkout_page' );
function cxc_remove_add_to_cart_message_checkout_page( $message ){
return '';
}
?>
Was this article helpful?
YesNo