diff --git a/admin/class-paypal-for-woocommerce-multi-account-management-admin-express-checkout.php b/admin/class-paypal-for-woocommerce-multi-account-management-admin-express-checkout.php index 57b79ce..7ef2f4b 100644 --- a/admin/class-paypal-for-woocommerce-multi-account-management-admin-express-checkout.php +++ b/admin/class-paypal-for-woocommerce-multi-account-management-admin-express-checkout.php @@ -324,6 +324,10 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew if ($line_item['subtotal'] != $line_item['total']) { $this->map_item_with_account[$product_id]['is_discountable'] = true; $this->angelleye_is_discountable = $this->angelleye_is_discountable + 1; + $discount_amount = $line_item['subtotal'] - $line_item['total']; + if($discount_amount > 0) { + $this->map_item_with_account[$product_id]['discount'] = $discount_amount; + } } else { $this->map_item_with_account[$product_id]['is_discountable'] = false; } @@ -449,6 +453,10 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew if ($cart_item['line_subtotal'] != $cart_item['line_total']) { $this->map_item_with_account[$product_id]['is_discountable'] = true; $this->angelleye_is_discountable = $this->angelleye_is_discountable + 1; + $discount_amount = $cart_item['line_subtotal'] - $cart_item['line_total']; + if($discount_amount > 0) { + $this->map_item_with_account[$product_id]['discount'] = $cart_item['line_subtotal'] - $cart_item['line_total']; + } } else { $this->map_item_with_account[$product_id]['is_discountable'] = false; } @@ -677,12 +685,11 @@ public function angelleye_modified_ec_parallel_parameter($request, $gateways, $o $this->taxamt = 0; } $this->shippingamt = round(WC()->cart->shipping_total, $this->decimals); - $this->discount_amount = round(WC()->cart->get_cart_discount_total(), $this->decimals); if (isset($this->shippingamt) && $this->shippingamt > 0) { if (!empty($this->map_item_with_account)) { $packages = WC()->shipping()->get_packages(); $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); - if(!empty($packages) && !empty($chosen_shipping_methods)) { + if(!empty($packages) && !empty($chosen_shipping_methods) && count($packages) > 1) { foreach ( $packages as $package_key => $package ) { if ( isset( $chosen_shipping_methods[ $package_key ], $package['rates'][ $chosen_shipping_methods[ $package_key ] ] ) ) { $shipping_rate = $package['rates'][ $chosen_shipping_methods[ $package_key ] ]; @@ -700,6 +707,7 @@ public function angelleye_modified_ec_parallel_parameter($request, $gateways, $o } $this->shipping_array = $this->angelleye_get_extra_fee_array($this->shippingamt, $this->angelleye_needs_shipping, 'shipping'); } + $this->discount_amount = round(WC()->cart->get_cart_discount_total(), $this->decimals); if (isset($this->discount_amount) && $this->discount_amount > 0) { $this->discount_array = $this->angelleye_get_extra_fee_array($this->discount_amount, $this->angelleye_is_discountable, 'discount'); } @@ -1520,7 +1528,7 @@ public function angelleye_get_extra_fee_array($amount, $divided, $type) { break; case "discount": if (!empty($item_with_account['is_discountable']) && $item_with_account['is_discountable'] === true) { - $partition_array[$product_id] = $partition_array[$loop]; + $partition_array[$product_id] = isset($item_with_account['discount']) ? $item_with_account['discount'] : $partition_array[$loop]; unset($partition_array[$loop]); $loop = $loop + 1; }