Created
August 14, 2013 09:34
-
-
Save jdevalk/6229418 to your computer and use it in GitHub Desktop.
Allow specification of a discount coupon through the URL, this means we can do away with the coupon field in the checkout process.
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 | |
/** | |
* Allow people to specify a coupon code in the URL, and add it to their cart. | |
*/ | |
function yst_edd_discount_link() { | |
if ( isset( $_GET['coupon'] ) ) { | |
// Check whether it's a valid coupon, if so, add it to the cart. | |
if ( edd_is_discount_valid( $_GET['coupon'] ) ) | |
edd_set_cart_discount( $_GET['coupon'] ); | |
// If we can redirect out the $_GET parameter, let's! | |
if ( is_singular() ) { | |
global $post; | |
wp_redirect( get_permalink( $post->ID ), 302 ); | |
} | |
} | |
} | |
add_action( 'template_redirect', 'yst_edd_discount_link' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment