Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Award Points on Order Completed
- * Award 100 points for each license a user purchases.
- * Licenses are a product variation.
- * @version 1.0
- */
- add_action( 'woocommerce_order_status_completed', 'mycred_pro_award_based_on_variation' );
- function mycred_pro_award_based_on_variation( $order_id ) {
- // Make sure myCRED is installed
- if ( ! function_exists( 'mycred' ) ) return;
- $order = new WC_Order( $order_id );
- $items = $order->get_items();
- $payout = 0;
- // Loop though the order items to count licenses
- foreach ( $items as $item ) {
- // Only applicable for products that have the variation "pa_license"
- if ( ! isset( $item['pa_license'] ) ) continue;
- if ( $item['pa_license'] == 'single-site-license' )
- $number = 1;
- elseif ( $item['pa_license'] == '5-site-licenses' )
- $number = 5;
- elseif ( $item['pa_license'] == '10-site-licenses' )
- $number = 10;
- else
- $number = 1;
- $payout = $payout + ( $number * 100 );
- }
- if ( $payout > 0 ) {
- $point_type = 'mycred_default';
- $mycred = mycred( $point_type );
- if ( ! $mycred->exclude_user( $order->user_id ) )
- $mycred->add_creds(
- 'store_reward',
- $order->user_id,
- $payout,
- 'Store purchase reward',
- $order_id,
- array( 'ref_id' => 'post' ),
- $point_type
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement