Skip to content

Instantly share code, notes, and snippets.

@amdrew
Created February 9, 2015 08:46
Show Gist options
  • Save amdrew/6d98891e0a958f71240f to your computer and use it in GitHub Desktop.
Save amdrew/6d98891e0a958f71240f to your computer and use it in GitHub Desktop.
Easy Digital Downloads - Add download to cart if the cart is empty
<?php
/**
* Add product to cart if cart is empty
*/
function sumobi_edd_add_to_cart_if_empty() {
$download_to_add = 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_to_add );
}
}
add_action( 'template_redirect', 'sumobi_edd_add_to_cart_if_empty', 9 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment