Skip to content

Commit

Permalink
fix: make product price float to remove warning when product price is…
Browse files Browse the repository at this point in the history
… empty string (#700)
  • Loading branch information
saimonh3 authored and sabbir1991 committed Nov 19, 2019
1 parent d181baf commit bf4813f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions includes/class-commission.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function get_earning_by_product( $product, $context = 'seller', $price =
return new WP_Error( __( 'Product not found', 'dokan-lite' ), 404 );
}

$product_price = is_null( $price ) ? $product->get_price() : $price;
$product_price = is_null( $price ) ? (float) $product->get_price() : (float) $price;
$vendor = dokan_get_vendor_by_product( $product );

$earning = $this->calculate_commission( $product->get_id(), $product_price, $vendor->get_id() );
Expand Down Expand Up @@ -521,16 +521,16 @@ public function prepare_for_calculation( $callable, $product_id = 0, $product_pr
$commission_rate = ( $commission_rate / $item_total ) * $product_price;
}

$earning = (float) ( $product_price - $commission_rate );
$earning = $product_price - $commission_rate;
}

if ( 'percentage' === $commission_type ) {
$earning = ( (float) $product_price * $commission_rate ) / 100;
$earning = (float) $product_price - $earning;
$earning = ( $product_price * $commission_rate ) / 100;
$earning = $product_price - $earning;

// vendor will get 100 percent if commission rate > 100
if ( $commission_rate > 100 ) {
$earning = (float) $product_price;
$earning = $product_price;
}
}

Expand Down

0 comments on commit bf4813f

Please sign in to comment.