Skip to content

Instantly share code, notes, and snippets.

@amdrew
Created March 18, 2015 15:15
Show Gist options
  • Save amdrew/1ab6521716837c193f9b to your computer and use it in GitHub Desktop.
Save amdrew/1ab6521716837c193f9b to your computer and use it in GitHub Desktop.
/**
* Restrict quantity of download at checkout
*/
function sumobi_edd_restrict_download_quantity( $valid_data, $post ) {
$download_id = 50;
$max_number = 4;
$cart_contents = edd_get_cart_contents();
if ( $cart_contents ) {
foreach ( $cart_contents as $download ) {
if ( $download['id'] == $download_id ) {
if ( $download['quantity'] > $max_number ) {
edd_set_error( 'invalid_quantity', sprintf( __( 'You cannot purchase more than %s of this download', 'edd' ), $max_number ) );
}
}
}
}
}
add_action( 'edd_checkout_error_checks', 'sumobi_edd_restrict_download_quantity', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment