Last active
December 29, 2020 06:27
-
-
Save gvgvgvijayan/7a19986dd29f0432e6fce8f82d906b87 to your computer and use it in GitHub Desktop.
This gist is used in the tutorial https://www.vijayan.in/how-to-limit-the-cart-quantity-of-discounted-product/
This file contains 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
<?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