Skip to content

Instantly share code, notes, and snippets.

View andrewreal's full-sized avatar

Andrew Real andrewreal

View GitHub Profile
@AshlinRejo
AshlinRejo / Discount rules v2: For getting discounted price of a product
Last active October 27, 2023 05:45
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