Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AshlinRejo/c37a155a42c0e30beafbbad183f0c4e8 to your computer and use it in GitHub Desktop.
Save AshlinRejo/c37a155a42c0e30beafbbad183f0c4e8 to your computer and use it in GitHub Desktop.
Discount rules v2: For getting discounted price of a product
/**
* 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
}
@mrizwan47
Copy link

Hey @AshlinRejo, in case of a bulk discount, do you know if we can ignore the current items in cart? And just get the discount_price for x quantities?

@mrizwan47
Copy link

Right now it calculates discount based on qty in cart + the $quantity param

@AshlinRejo
Copy link
Author

AshlinRejo commented Jun 2, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment