Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * myCRED Profit Share for Woo
- * Replaces the default profit share system in myCRED for WooCommerce
- * orders to payout the "line_subtotal" instead of "line_total".
- * @version 1.0
- */
- add_action( 'mycred_paid_for_woo', 'mycred_pro_woo_profit_payouts', 10, 3 );
- function mycred_pro_woo_profit_payouts( $order, $user, $gateway ) {
- // Default Profit Share ( in percentage )
- $profit_share = 70;
- // Get Items
- $items = $order->get_items();
- // Loop though items
- foreach ( $items as $item ) {
- // Get Product
- $product = get_post( (int) $item['product_id'] );
- // Continue if product has just been deleted or owner is buyer
- if ( $product === NULL || $product->post_author == $user ) continue;
- // Calculate Share and let others play
- $percentage = apply_filters( 'mycred_woo_profit_share', $profit_share, $order, $product, $gateway );
- if ( $percentage == 0 ) continue;
- // Sub total instead of total should exclude coupon usage
- $share = ( $percentage / 100 ) * $item['line_subtotal'];
- // Payout
- $gateway->mycred->add_creds(
- 'store_sale',
- $product->post_author,
- $share,
- $gateway->profit_sharing_log,
- $product->ID,
- array( 'ref_type' => 'post' ),
- $gateway->mycred_type
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement