Skip to content

Instantly share code, notes, and snippets.

@gvgvgvijayan
Last active December 29, 2020 06:27
Show Gist options
  • Save gvgvgvijayan/7a19986dd29f0432e6fce8f82d906b87 to your computer and use it in GitHub Desktop.
Save gvgvgvijayan/7a19986dd29f0432e6fce8f82d906b87 to your computer and use it in GitHub Desktop.
<?php
/**
* Validation function to limit the quantity.
*
* @param int $product_id Product ID.
* @param int $quantity Product quantity.
* @param string $action_type Type of the action. Allowed 'add' or 'update'.
*
* @return bool Return true if quantity is not exceeded else false.
*/
function validate_product_qty( $product_id, $quantity, $action_type ) {
if ( is_discounted_prdct_qty_exceeded( $product_id, $quantity, $action_type ) ) {
$output_string = wp_sprintf(
'%s %d.',
__( 'Discounted product maximum quantity is ' ),
MAX_QUANTITY
);
wc_add_notice( $output_string, 'notice' );
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment