Created
March 18, 2015 15:15
-
-
Save amdrew/1ab6521716837c193f9b to your computer and use it in GitHub Desktop.
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
/** | |
* 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