Last active
July 29, 2021 14:51
-
-
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).
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
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have the filter needed in subscription "Review Now" so that it goes to the cart instead of the checkout page