Skip to content

Instantly share code, notes, and snippets.

@jdevalk
Created August 14, 2013 09:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdevalk/6229418 to your computer and use it in GitHub Desktop.
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.
<?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