Advertisement
designbymerovingi

Example: Payout 25% of orders subtotal in points.

Jun 15th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. add_action( 'woocommerce_order_status_completed', 'mycredpro_woo_purchase_reward' );
  2. function mycredpro_woo_purchase_reward( $order_id ) {
  3.  
  4.     if ( ! function_exists( 'mycred' ) ) return;
  5.  
  6.     $order = wc_get_order( $order_id );
  7.  
  8.     // Do not payout if order was paid using points
  9.     if ( $order->payment_method == 'mycred' ) return;
  10.  
  11.     // Get total
  12.     $cost = $order->get_subtotal();
  13.  
  14.     $mycred = mycred();
  15.  
  16.     // Make sure user only gets points once per order
  17.     if ( $mycred->has_entry( 'shopping_reward', $order_id, $order->user_id ) ) return;
  18.  
  19.     // Reward example 25% in points.
  20.     $reward = $cost * 0.25;
  21.  
  22.     // Add reward
  23.     $mycred->add_creds(
  24.         'shopping_reward',
  25.         $order->user_id,
  26.         $reward,
  27.         'Reward for store purchase',
  28.         $order_id,
  29.         array( 'ref_type' => 'post' )
  30.     );
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement