<?php
/**
* Woo Point Rewards by Order Total
* Reward store purchases by paying a percentage of the order total
* as points to the buyer.
* @version 1.1
*/
function mycred_pro_reward_order_percentage( $order_id ) {
if ( ! function_exists( 'mycred' ) ) return;
// Get Order
$order = wc_get_order( $order_id );
$cost = $order->get_total();
// Do not payout if order was paid using points
if ( $order->payment_method == 'mycred' ) return;
// The percentage to payout
$percent = 100;
// Load myCRED
$mycred = mycred();
// Make sure user only gets points once per order
if ( $mycred->has_entry( 'reward', $order_id, $order->user_id ) ) return;
// Reward example 100% in points.
$reward = round($cost * ( $percent / 100 ));
// Add reward
$mycred->add_creds(
'reward',
$order->user_id,
$reward,
'Reward for MCC online store purchase',
$order_id,
array( 'ref_type' => 'post' )
);
}
add_action( 'woocommerce_order_status_shipped', 'mycred_pro_reward_order_percentage' ); // woocommerce_order_status_<any order status>