Skip to content

Commit

Permalink
fix: return 0 if product price is not given is fixed #626 (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
saimonh3 authored and sabbir1991 committed Jun 10, 2019
1 parent 9d9f1a6 commit e409996
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,7 @@ function dokan_cache_clear_deleted_product( $post_id ) {
*
* @param int $seller_id
*
* @return int $earning;
* @return float $earning | zero on failure or no price
*/
function dokan_get_earning_by_product( $product_id, $seller_id ) {
$product = wc_get_product( $product_id );
Expand All @@ -2803,7 +2803,12 @@ function dokan_get_earning_by_product( $product_id, $seller_id ) {
$percentage = dokan_get_seller_percentage( $seller_id, $product_id );
$percentage_type = dokan_get_commission_type( $seller_id, $product_id );
$price = $product->get_price();
$earning = 'percentage' == $percentage_type ? (float) ( $price * $percentage ) / 100 : $price - $percentage;

if ( ! $price || 0 > $price ) {
return 0;
}

$earning = 'percentage' == $percentage_type ? (float) ( $price * $percentage ) / 100 : $price - $percentage;

return wc_format_decimal( $earning );
}
Expand Down

0 comments on commit e409996

Please sign in to comment.