add_filter( 'woocommerce_add_to_cart_redirect', function( $wc_cart_url ) {
// Check Cart Total
if( isset( WC()->cart->total ) && WC()->cart->total == 0 ) {
return wc_get_checkout_url();
}
// Return
return $wc_cart_url;
} );
Or, for redirecting from product pages only (not from shop or category archives):
add_filter( 'woocommerce_add_to_cart_redirect', function( $url ) {
if(
! empty( $_SERVER['HTTP_REFERER'] )
&& strstr( $_SERVER['HTTP_REFERER'], '/product/' ) !== false
) {
return wc_get_cart_url();
}
return $url;
} );
We code all of our code snippets directly. Our clients provide most of the ideas and demand for the functionality provided by our code snippets.
There are several sources one can find on Google for code that has inspired or contributed to this open-source library. Here’s some main ones:
All code snippets are licensed GPLv2 (or later) matching WordPress licensing.
Disclaimer of warranty:
Except when otherwise stated in writing the copyright holders and/or other parties provide the program as-is without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose.