Add the below function to your functions.php for your theme. It will return a 2d associative array in the form of…
Array ( [0] => Array ( [quantity] => 0 [discount] => 0 ) [1] => Array ( [quantity] => 3 [discount] => 60 ) [2] => Array ( [quantity] => 4 [discount] => 160 ) [3] => Array ( [quantity] => 5 [discount] => 300 ) [4] => Array ( [quantity] => 6 [discount] => 420 ) )
This is all the discounts associated with a product. You can call this function in your functions.php.
Even better would be to add it to the plugin as a static function so it can be called from any templete file.
DEVELOPER..CAN YOU PLEASE ADD THIS TO THE PLUGIN IN THE NEXT RELEASE.
I am not yelling. ??
function get_product_discount( $product_id ) {
global $woocommerce;
$quantity_discount = array( array(‘quantity’=>0.0, ‘discount’=>0.0) );
/* Find the appropriate discount coefficient by looping through up to the five discount settings */
for ( $i = 1; $i <= 5; $i++ ) {
if ( get_post_meta( $product_id, “_bulkdiscount_quantity_$i”, true ) ) {
$q = get_post_meta( $product_id, “_bulkdiscount_quantity_$i”, true );
if ( get_option( ‘woocommerce_t4m_discount_type’, ” ) == ‘flat’ ) {
$d = get_post_meta( $product_id, “_bulkdiscount_discount_flat_$i”, true ) ? max( 0, get_post_meta( $product_id, “_bulkdiscount_discount_flat_$i”, true ) ): 0.0;
} else {
$d = get_post_meta( $product_id, “_bulkdiscount_discount_$i”, true ) ? min( 1.0, max( 0, ( 100.0 – round( get_post_meta( $product_id, “_bulkdiscount_discount_$i”, true ), 2 ) ) / 100.0 ) ) : 0.0;
}
array_push($quantity_discount, array(‘quantity’=>$q, ‘discount’=>$d));
}
}
return $quantity_discount;
}