Forked from gabrielmerovingi/reward-completed-woo-orders
Created
February 19, 2019 12:38
-
-
Save tharlab/ef1396047f812cbbb35076fd6e024a8f to your computer and use it in GitHub Desktop.
Example: Reward buyer with 1 point for each product in an order, once the order is marked as completed. Requires WooCommerce 3.0+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Reward Completed Orders | |
* Will give a user 1 point for each product in an order. | |
* @version 1.0.1 | |
*/ | |
function mycred_pro_reward_completed_orders( $order_id ) { | |
if ( ! function_exists( 'mycred' ) ) return; | |
$order = wc_get_order( $order_id ); | |
$user_id = $order->get_user_id(); | |
$point_type_key = 'something'; | |
$mycred = mycred( $point_type_key ); | |
if ( ! $mycred->exclude_user( $user_id ) ) { | |
foreach ( $order->get_items() as $item ) { | |
$mycred->add_creds( | |
'book_return', | |
$user_id, | |
1, | |
'Returned book', | |
$item['product_id'], | |
array( 'ref_type' => 'post' ), | |
$point_type_key | |
); | |
} | |
} | |
} | |
add_action( 'woocommerce_order_status_completed', 'mycred_pro_reward_completed_orders' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment