Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_order_status_completed', 'mycredpro_woo_purchase_reward' );
- function mycredpro_woo_purchase_reward( $order_id ) {
- if ( ! function_exists( 'mycred' ) ) return;
- $order = wc_get_order( $order_id );
- // Do not payout if order was paid using points
- if ( $order->payment_method == 'mycred' ) return;
- // Get total
- $cost = $order->get_subtotal();
- $mycred = mycred();
- // Make sure user only gets points once per order
- if ( $mycred->has_entry( 'shopping_reward', $order_id, $order->user_id ) ) return;
- // Reward example 25% in points.
- $reward = $cost * 0.25;
- // Add reward
- $mycred->add_creds(
- 'shopping_reward',
- $order->user_id,
- $reward,
- 'Reward for store purchase',
- $order_id,
- array( 'ref_type' => 'post' )
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement