Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function get_item_commission($product_id, $variation_id, $item, $order_id, $item_id = '') {
- global $WCMp;
- $order = wc_get_order($order_id);
- $amount = 0;
- $commission = array();
- $commission_rule = array();
- $product_value_total = 0;
- // Check order coupon created by vendor or not
- $order_counpon_author_is_vendor = false;
- if ($order->get_coupon_codes()) {
- foreach( $order->get_coupon_codes() as $coupon_code ) {
- $coupon = new WC_Coupon($coupon_code);
- $order_counpon_author_is_vendor = $coupon && is_user_wcmp_vendor( get_post_field ( 'post_author', $coupon->get_id() ) ) ? true : false;
- }
- }
- $line_discount = 0;
- if (isset($WCMp->vendor_caps->payment_cap['commission_include_coupon'])) {
- //$line_total = $order->get_item_total($item, false, false) * $item['qty'];
- $line_total = $order->get_item_subtotal($item, false, false) * $item['qty'];
- $line_discount = ($order->get_item_subtotal($item, false, false) - $order->get_item_total($item, false, false)) * $item['qty'];
- /*if (isset($WCMp->vendor_caps->payment_cap['admin_coupon_excluded']) && !$order_counpon_author_is_vendor) {
- $line_total = $order->get_item_subtotal($item, false, false) * $item['qty'];
- }*/
- } else {
- $line_total = $order->get_item_subtotal($item, false, false) * $item['qty'];
- }
- // Filter the item total before calculating item commission.
- $line_total = apply_filters('wcmp_get_commission_line_total', $line_total, $product_id, $variation_id, $item, $order_id, $item_id);
- if ($product_id) {
- $vendor_id = wc_get_order_item_meta($item_id, '_vendor_id', true);
- if ($vendor_id) {
- $vendor = get_wcmp_vendor($vendor_id);
- } else {
- $vendor = get_wcmp_product_vendors($product_id);
- }
- if ($vendor) {
- $commission = $this->get_commission_amount($product_id, $vendor->term_id, $variation_id, $item_id, $order);
- $commission = apply_filters('wcmp_get_commission_amount', $commission, $product_id, $vendor->term_id, $variation_id, $item_id, $order);
- if (!empty($commission)) {
- if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage') {
- $amount = (float) $line_total * ( (float) $commission['commission_val'] / 100 ) + (float) $commission['commission_fixed'];
- } else if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage_qty') {
- $amount = (float) $line_total * ( (float) $commission['commission_val'] / 100 ) + ((float) $commission['commission_fixed'] * $item['qty']);
- } else if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'percent') {
- $amount = (float) $line_total * ( (float) $commission['commission_val'] / 100 );
- } else if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed') {
- $amount = (float) $commission['commission_val'] * $item['qty'];
- } elseif ($WCMp->vendor_caps->payment_cap['commission_type'] == 'commission_by_product_price') {
- $amount = $this->wcmp_get_commission_as_per_product_price($product_id, $line_total, $item['qty'], $commission_rule);
- } elseif ($WCMp->vendor_caps->payment_cap['commission_type'] == 'commission_by_purchase_quantity') {
- $amount = $this->wcmp_get_commission_rule_by_quantity_rule($product_id, $line_total, $item['qty'], $commission_rule);
- }
- if (isset($WCMp->vendor_caps->payment_cap['revenue_sharing_mode'])) {
- if ($WCMp->vendor_caps->payment_cap['revenue_sharing_mode'] == 'admin') {
- $amount = (float) $line_total - (float) $amount - (float) $line_discount;
- if ($amount < 0) {
- $amount = 0;
- }
- }
- }
- if ($variation_id == 0 || $variation_id == '') {
- $product_id_for_value = $product_id;
- } else {
- $product_id_for_value = $variation_id;
- }
- $product_value_total += $item->get_total();
- if ( apply_filters('wcmp_admin_pay_commission_more_than_order_amount', true) && $amount > $product_value_total) {
- $amount = $product_value_total;
- }
- return apply_filters('vendor_commission_amount', $amount, $product_id, $variation_id, $item, $order_id, $item_id);
- }
- }
- }
- return apply_filters('vendor_commission_amount', $amount, $product_id, $variation_id, $item, $order_id, $item_id);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement