mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://stackoverflow.com/questions/65690440/custom-redirections-to-make-the-cart-page-inaccessible-in-woocommerce
12 lines
329 B
Text
12 lines
329 B
Text
add_action('template_redirect', 'custom_cart_redirections');
|
|
function custom_cart_redirections() {
|
|
if ( is_cart() ) {
|
|
if ( WC()->cart->is_empty() ) {
|
|
wp_redirect( home_url('/') );
|
|
exit();
|
|
} else {
|
|
wp_redirect( wc_get_checkout_url() );
|
|
exit();
|
|
}
|
|
}
|
|
}
|