Advertisement
designbymerovingi

Pay 2% of Woo order total in myCRED points

Mar 30th, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. /**
  2.  * Point Payout
  3.  * Pay 2% of the order total as points to buyer.
  4.  * Will only pay if:
  5.  * - Buyer is logged in
  6.  * - Buyer pays using a non-manual payment gateway
  7.  * - Buyer is not excluded from using myCRED
  8.  * - myCRED is enabled
  9.  *
  10.  * @version 1.0
  11.  */
  12. add_action( 'woocommerce_payment_complete', 'mycred_pro_woo_purchase_reward' );
  13. function mycred_pro_woo_purchase_reward( $order_id )
  14. {
  15.     if ( ! function_exists( 'mycred' ) ) return;
  16.  
  17.     $order = new WC_Order( $order_id );
  18.     if ( $order->order_total == 0.00 || $order->order_total == 0 ) return;
  19.  
  20.     $point_type = 'mycred_default';
  21.     $mycred     = mycred( $point_type );
  22.  
  23.     // Make sure buyer only get points once per order
  24.     if ( $mycred->has_entry( 'shopping_reward', $order_id, $order->user_id ) ) return;
  25.  
  26.     // Add reward
  27.     $mycred->add_creds(
  28.         'shopping_reward',
  29.         $order->user_id,
  30.         ( $order->order_total * 0.02 ),
  31.         'Reward for store purchase',
  32.         $order_id,
  33.         array( 'ref_type' => 'post' ),
  34.         $point_type
  35.     );
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement