Created
December 18, 2014 04:43
-
-
Save amdrew/07cec5563ab95720dca5 to your computer and use it in GitHub Desktop.
Easy Digital Downloads - Add specific download to cart if it doesn't already exist
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 | |
/** | |
* Add a specific download to the cart if not already there | |
*/ | |
function sumobi_edd_add_download_to_cart_if_empty() { | |
$download_id = 123; | |
$cart = function_exists( 'edd_get_cart_contents' ) ? edd_get_cart_contents() : false; | |
if ( function_exists( 'edd_is_checkout' ) && edd_is_checkout() && ! $cart ) { | |
edd_add_to_cart( $download_id, array( 'price_id' => 0 ) ); | |
} | |
} | |
add_action( 'template_redirect', 'sumobi_edd_add_download_to_cart_if_empty' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment