Created
March 2, 2015 03:44
-
-
Save mattallan/2a7678c2508f5c646593 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 hidden or 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 ) { | |
global $woocommerce; | |
// 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 = $woocommerce->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