Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Pay 2 Points / Product
- * Rewards a buyer with 2 points per product they purchase
- * using WooCommerce.
- * @version 1.0
- */
- add_action( 'woocommerce_payment_complete', 'mycred_pro_add_points_for_product_purchase' );
- function mycred_pro_add_points_for_product_purchase( $order_id ) {
- if ( ! function_exists( 'mycred' ) ) return;
- $order = wc_get_order( $order_id );
- if ( $order->order_total == 0.00 || $order->order_total == 0 || $order->payment_method == 'mycred' ) return;
- $point_type = 'mycred_default';
- $mycred = mycred( $point_type );
- if ( $mycred->has_entry( 'shopping_reward', $order_id, $order->user_id ) ) return;
- // Calculate reward
- $reward = 0;
- $items = $order->get_items();
- foreach ( $items as $item ) {
- $reward += 2 * $item['qty'];
- }
- // Add reward
- $mycred->add_creds(
- 'shopping_reward',
- $order->user_id,
- $reward,
- 'Reward for store purchase',
- $order_id,
- array( 'ref_type' => 'post' ),
- $point_type
- );
- $message = '%s points paid as reward';
- $message = str_replace( '%s', $mycred->format_creds( $reward ), $message );
- $order->add_order_note( $message, 1 );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement