Skip to content

Instantly share code, notes, and snippets.

@anhducbkhn
Last active June 20, 2017 09:49
Show Gist options
  • Save anhducbkhn/fddaea578e3163fe4e6df4e042b6524d to your computer and use it in GitHub Desktop.
Save anhducbkhn/fddaea578e3163fe4e6df4e042b6524d to your computer and use it in GitHub Desktop.
Force user to redirect to cart page in woocommerce
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