Advertisement
Guest User

Untitled

a guest
Oct 19th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. public function get_item_commission($product_id, $variation_id, $item, $order_id, $item_id = '') {
  2. global $WCMp;
  3. $order = wc_get_order($order_id);
  4. $amount = 0;
  5. $commission = array();
  6. $commission_rule = array();
  7. $product_value_total = 0;
  8. // Check order coupon created by vendor or not
  9. $order_counpon_author_is_vendor = false;
  10. if ($order->get_coupon_codes()) {
  11. foreach( $order->get_coupon_codes() as $coupon_code ) {
  12. $coupon = new WC_Coupon($coupon_code);
  13. $order_counpon_author_is_vendor = $coupon && is_user_wcmp_vendor( get_post_field ( 'post_author', $coupon->get_id() ) ) ? true : false;
  14. }
  15. }
  16.  
  17. $line_discount = 0;
  18. if (isset($WCMp->vendor_caps->payment_cap['commission_include_coupon'])) {
  19. //$line_total = $order->get_item_total($item, false, false) * $item['qty'];
  20. $line_total = $order->get_item_subtotal($item, false, false) * $item['qty'];
  21. $line_discount = ($order->get_item_subtotal($item, false, false) - $order->get_item_total($item, false, false)) * $item['qty'];
  22.  
  23. /*if (isset($WCMp->vendor_caps->payment_cap['admin_coupon_excluded']) && !$order_counpon_author_is_vendor) {
  24. $line_total = $order->get_item_subtotal($item, false, false) * $item['qty'];
  25. }*/
  26. } else {
  27. $line_total = $order->get_item_subtotal($item, false, false) * $item['qty'];
  28. }
  29.  
  30. // Filter the item total before calculating item commission.
  31. $line_total = apply_filters('wcmp_get_commission_line_total', $line_total, $product_id, $variation_id, $item, $order_id, $item_id);
  32.  
  33. if ($product_id) {
  34. $vendor_id = wc_get_order_item_meta($item_id, '_vendor_id', true);
  35. if ($vendor_id) {
  36. $vendor = get_wcmp_vendor($vendor_id);
  37. } else {
  38. $vendor = get_wcmp_product_vendors($product_id);
  39. }
  40. if ($vendor) {
  41. $commission = $this->get_commission_amount($product_id, $vendor->term_id, $variation_id, $item_id, $order);
  42. $commission = apply_filters('wcmp_get_commission_amount', $commission, $product_id, $vendor->term_id, $variation_id, $item_id, $order);
  43. if (!empty($commission)) {
  44. if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage') {
  45. $amount = (float) $line_total * ( (float) $commission['commission_val'] / 100 ) + (float) $commission['commission_fixed'];
  46. } else if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage_qty') {
  47. $amount = (float) $line_total * ( (float) $commission['commission_val'] / 100 ) + ((float) $commission['commission_fixed'] * $item['qty']);
  48. } else if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'percent') {
  49. $amount = (float) $line_total * ( (float) $commission['commission_val'] / 100 );
  50. } else if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed') {
  51. $amount = (float) $commission['commission_val'] * $item['qty'];
  52. } elseif ($WCMp->vendor_caps->payment_cap['commission_type'] == 'commission_by_product_price') {
  53. $amount = $this->wcmp_get_commission_as_per_product_price($product_id, $line_total, $item['qty'], $commission_rule);
  54. } elseif ($WCMp->vendor_caps->payment_cap['commission_type'] == 'commission_by_purchase_quantity') {
  55. $amount = $this->wcmp_get_commission_rule_by_quantity_rule($product_id, $line_total, $item['qty'], $commission_rule);
  56. }
  57. if (isset($WCMp->vendor_caps->payment_cap['revenue_sharing_mode'])) {
  58. if ($WCMp->vendor_caps->payment_cap['revenue_sharing_mode'] == 'admin') {
  59. $amount = (float) $line_total - (float) $amount - (float) $line_discount;
  60. if ($amount < 0) {
  61. $amount = 0;
  62. }
  63. }
  64. }
  65. if ($variation_id == 0 || $variation_id == '') {
  66. $product_id_for_value = $product_id;
  67. } else {
  68. $product_id_for_value = $variation_id;
  69. }
  70.  
  71. $product_value_total += $item->get_total();
  72. if ( apply_filters('wcmp_admin_pay_commission_more_than_order_amount', true) && $amount > $product_value_total) {
  73. $amount = $product_value_total;
  74. }
  75. return apply_filters('vendor_commission_amount', $amount, $product_id, $variation_id, $item, $order_id, $item_id);
  76. }
  77. }
  78. }
  79. return apply_filters('vendor_commission_amount', $amount, $product_id, $variation_id, $item, $order_id, $item_id);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement