Skip to content

Instantly share code, notes, and snippets.

@amdrew
Created December 18, 2014 04:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amdrew/07cec5563ab95720dca5 to your computer and use it in GitHub Desktop.
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
<?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