Last active
June 20, 2017 09:49
-
-
Save anhducbkhn/fddaea578e3163fe4e6df4e042b6524d to your computer and use it in GitHub Desktop.
Force user to redirect to cart page in woocommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('template_redirect', 'redirect_to_cart_page'); | |
function redirect_to_cart_page() | |
{ | |
if (is_checkout() and !is_user_logged_in()) { | |
$carts = WC()->cart->get_cart(); | |
if (!empty($carts)) { | |
foreach ( $carts as $cart) | |
{ | |
// Condition | |
if( array_key_exists($cart['product_id'], SUBSCRIPTIONS_PRODUCT) || $cart['product_id'] == 925) { | |
wp_redirect( home_url( '/cart/' ) ); | |
exit(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment