Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.