Last active
January 10, 2017 12:58
-
-
Save simonlk/26856ec9113c7e1955801f2a87d001f5 to your computer and use it in GitHub Desktop.
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 Checkout | |
* Description: Redirect customers to the checkout page when adding a subscription to their cart (rather than the checkout page, which is the default). | |
* Author: Simon Kelly | |
* Author URI: http://www.renegade-empire.com | |
* Version: 1.0 | |
* License: GPL v2 | |
*/ | |
function re_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 checkout instead | |
$url = WC()->cart->get_checkout_url(); | |
} | |
return $url; | |
} | |
add_filter( 'woocommerce_add_to_cart_redirect', 're_redirect_to_cart_page', 20 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment