Skip to content

Instantly share code, notes, and snippets.

@thenbrent
Last active July 29, 2021 14:51
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thenbrent/7254424 to your computer and use it in GitHub Desktop.
Save thenbrent/7254424 to your computer and use it in GitHub Desktop.
Redirect customers to the cart page when adding a subscription to their cart (rather than the checkout page, which is the default).
<?php
/**
* Plugin Name: WooCommerce Subscriptions Redirect to Cart
* Description: Redirect customers to the cart page when adding a subscription to their cart (rather than the checkout page, which is the default).
* Author: Gerhard Potgieter & Brent Shepherd
* Author URI: http://www.woothemes.com/products/woocommerce-subscriptions/
* Version: 1.0
* License: GPL v2
*/
function eg_redirect_to_cart_page( $url ) {
// If product is of the subscription type
if ( is_numeric( $_REQUEST['add-to-cart'] ) && WC_Subscriptions_Product::is_subscription( (int) $_REQUEST['add-to-cart'] ) ) {
// Redirect to cart instead
$url = WC()->cart->get_cart_url();
}
return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'eg_redirect_to_cart_page', 20 );
@phxlad
Copy link

phxlad commented Apr 6, 2020

Do you have the filter needed in subscription "Review Now" so that it goes to the cart instead of the checkout page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment