Advertisement
designbymerovingi

myCRED Profit Share for Woo

Jan 2nd, 2015
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /**
  2. * myCRED Profit Share for Woo
  3. * Replaces the default profit share system in myCRED for WooCommerce
  4. * orders to payout the "line_subtotal" instead of "line_total".
  5. * @version 1.0
  6. */
  7. add_action( 'mycred_paid_for_woo', 'mycred_pro_woo_profit_payouts', 10, 3 );
  8. function mycred_pro_woo_profit_payouts( $order, $user, $gateway ) {
  9.  
  10. // Default Profit Share ( in percentage )
  11. $profit_share = 70;
  12.  
  13. // Get Items
  14. $items = $order->get_items();
  15.  
  16. // Loop though items
  17. foreach ( $items as $item ) {
  18.  
  19. // Get Product
  20. $product = get_post( (int) $item['product_id'] );
  21.  
  22. // Continue if product has just been deleted or owner is buyer
  23. if ( $product === NULL || $product->post_author == $user ) continue;
  24.  
  25. // Calculate Share and let others play
  26. $percentage = apply_filters( 'mycred_woo_profit_share', $profit_share, $order, $product, $gateway );
  27. if ( $percentage == 0 ) continue;
  28.  
  29. // Sub total instead of total should exclude coupon usage
  30. $share = ( $percentage / 100 ) * $item['line_subtotal'];
  31.  
  32. // Payout
  33. $gateway->mycred->add_creds(
  34. 'store_sale',
  35. $product->post_author,
  36. $share,
  37. $gateway->profit_sharing_log,
  38. $product->ID,
  39. array( 'ref_type' => 'post' ),
  40. $gateway->mycred_type
  41. );
  42.  
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement