Haven't yet purchased the Discount Rules for WooCommerce - PRO ?
Let's get started,
To get discount details of a product in shop, category, loop, and product pages by using product object or id
1. To get discount price of a product
global $product;
$sale_price = $product->get_price();
/**
* Get the discount price of a product
* @param $sale_price float|integer
* @param $product object[wc_get_product($product_id))]|integer
* @return float|integer
*/
$sale_price = apply_filters('advanced_woo_discount_rules_get_product_discount_price', $sale_price, $product);
2. To get discount price of a product based on product quantity
global $product;
$sale_price = $product->get_price();
$quantity = 2;
/**
* Get the discount price of a product based on quantity
* @param $sale_price float|integer
* @param $product object[wc_get_product($product_id))]|integer
* @param $quantity integer
* @return float|integer
*/
$sale_price = apply_filters('advanced_woo_discount_rules_get_product_discount_price', $sale_price, $product, $quantity);
3. To get discount price of a product based on product quantity and custom price
global $product;
$sale_price = $product->get_price();
$quantity = 2;
$custom_price = 100;
/**
* Get the discount price of a product based on quantity with custom price
* @param $sale_price float|integer
* @param $product object[wc_get_product($product_id))]|integer
* @param $quantity integer
* @param $custom_price float|integer
* @return float|integer
*/
$sale_price = apply_filters('advanced_woo_discount_rules_get_product_discount_price', $sale_price, $product, $quantity, $custom_price);
4. To get discount details of a product
/**
* Get the discount details of a product
* @param false
* @param $product object[wc_get_product($product_id))]|integer
* @param $quantity integer [optional]
* @param $custom_price float|integer [optional]
* @return array|false - Returns false if there is no discount
*/
$discount_details = apply_filters('advanced_woo_discount_rules_get_product_discount_details', false, $product);
if ($discount_details !== false) {
print_r($discount_details); // here you can get discount details
}
5. To get discount percentage of a product
/**
* Get the discount percentage of a product
* @param 0
* @param $product object[wc_get_product($product_id))]|integer
* @return float|int - Returns 0 if there is no discount
*/
$discount_percentage = apply_filters('advanced_woo_discount_rules_get_product_discount_percentage', 0, $product);
if ($discount_percentage > 0) {
echo $discount_percentage; // here you can get discount percentage
}
6. To get save amount of a product
/**
* Get save amount of a product
* @param 0
* @param $product object[wc_get_product($product_id))]|integer
* @return float|int - Returns 0 if there is no discount
*/
$save_amount = apply_filters('advanced_woo_discount_rules_get_product_save_amount', 0, $product);
if ($save_amount > 0) {
echo $save_amount; // here you can get save amount
}
Get discount details of a product in cart and checkout pages by using cart item array or key
1. To get discount price of a cart item
/**
* Get discount price of a cart item
* @param false
* @param $cart_item array [cart item from the cart] | string [An identifier for the item (cart item key or line item ID)]
* @return float|int|boolean - Returns false if there is no discount
*/
$discount_price = apply_filters('advanced_woo_discount_rules_get_cart_item_discount_price', false, $cart_item);
if ($discount_price !== false) {
echo $discount_price; // here you can get discount price
}
You can also pass cart item key instead of cart item array
2. To get discount details of a cart item
/**
* Get discount details of a cart item
* @param false
* @param $cart_item array [cart item from the cart] | string [An identifier for the item (cart item key or line item ID)]
* @return array|boolean - Returns false if there is no discount
*/
$discount_details = apply_filters('advanced_woo_discount_rules_get_cart_item_discount_details', false, $cart_item);
if ($discount_details !== false) {
print_r($discount_details); // here you can get discount details
}
3. To get save amount of a cart item
/**
* Get save amount of a cart item
* @param 0
* @param $cart_item array [cart item from the cart] | string [An identifier for the item (cart item key or line item ID)]
* @return float|int - Returns 0 if there is no discount
*/
$save_amount = apply_filters('advanced_woo_discount_rules_get_cart_item_saved_amount', 0, $cart_item);
if ($save_amount > 0) {
echo $save_amount; // here you can get save amount
}
Get discount details of a product in order, email templates and order-received pages by using order item object or id
1. To get discount price of an order item
/**
* Get discount price of an order item
* @param false
* @param $order_item array [order item from the order] | integer [order item ID]
* @return float|int|boolean - Returns false if there is no discount
*/
$discount_price = apply_filters('advanced_woo_discount_rules_get_order_item_discount_price', false, $order_item);
if ($discount_price !== false) {
echo $discount_price; // here you can get discount price
}
2. To get discount details of an order item
/**
* Get discount details of an order item
* @param false
* @param $order_item array [order item from the order] | integer [order item ID]
* @return array|boolean - Returns false if there is no discount
*/
$discount_details = apply_filters('advanced_woo_discount_rules_get_order_item_discount_details', false, $order_item);
if ($discount_details !== false) {
print_r($discount_details); // here you can get discount details
}
3. To get save amount of an order item
/**
* Get save amount of an order item
* @param 0
* @param $order_item array [order item from the order] | integer [order item ID]
* @return float|int - Returns 0 if there is no discount
*/
$save_amount = apply_filters('advanced_woo_discount_rules_get_order_item_saved_amount', 0, $order_item);
if ($save_amount > 0) {
echo $save_amount; // here you can get save amount
}
Get total discount details of an order in order, email templates and order-received pages by using order object or id
1. To get discount details of an order
/**
* Get discount details of an order
* @param false
* @param $order object [WC_Order] | integer [order ID]
* @return array|boolean - Returns false if there is no discount
*/
$discount_details = apply_filters('advanced_woo_discount_rules_get_order_discount_details', false, $order);
if ($discount_details !== false) {
print_r($discount_details); // here you can get discount details
}
2. To get saved amount of an order
/**
* Get saved amount of an order
* @param 0
* @param $order object [WC_Order] | integer [order ID]
* @return float|int - Returns 0 if there is no discount
*/
$save_amount = apply_filters('advanced_woo_discount_rules_get_order_saved_amount', 0, $order);
if ($save_amount > 0) {
echo $save_amount; // here you can get save amount
}
Get Discount Rules PRO from here
Next Steps :
You may also want to check out these helpful guides:
Still unclear?
If you need any assistance, please create a support request at our ticket system. We are always happy to assist you :)