Last active
October 27, 2023 05:45
-
-
Save AshlinRejo/c37a155a42c0e30beafbbad183f0c4e8 to your computer and use it in GitHub Desktop.
Discount rules v2: For getting discounted price of a 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
/** | |
* Get the discount details of given product with custom price | |
* @param $price float/integer | |
* @param $product object (Product object Example: wc_get_product($product_id)) | |
* @param $quantity int | |
* @param $custom_price float/integer (0 for calculate discount from product price) | |
* @param $return_details string (Default value 'discounted_price' accepted values = 'discounted_price','all') | |
* @param $manual_request boolean (Default value false: pass this as true for get discount even if there is no item in cart) | |
* @param $is_cart boolean (Default value true) | |
* @return array|float|int - is product has no discounts, returns $price;else return array of discount details based on $return_details | |
*/ | |
$discount = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', $price, $product, $quantity, $custom_price, $return_details, $manual_request, $is_cart); | |
if($discount !== false){ | |
//$discount -> Here we get discount amount | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right now it calculates discount based on qty in cart + the $quantity param