/** * Handle an order that is cancelled or refunded by: * * 1) Removing any points earned for the order * * 2) Crediting points redeemed for a discount back to the customer's account if the order that they redeemed the points * for a discount on is cancelled or refunded * * @since 1.0 * @param int $order_id the WC_Order ID */ public function handle_cancelled_refunded_order($order_id) { global $wc_points_rewards; $order = new WC_Order($order_id); // bail for guest user if (!$order->user_id) { return; } // handle removing any points earned for the order $points_earned = get_post_meta($order->id, '_wc_points_earned', true); if ($points_earned > 0) { // remove points WC_Points_Rewards_Manager::decrease_points($order->user_id, $points_earned, 'order-cancelled', null, $order->id); // remove points from order delete_post_meta($order->id, '_wc_points_earned'); // add order note $order->add_order_note(sprintf(__('%d %s removed.', 'wc_points_rewards'), $points_earned, $wc_points_rewards->get_points_label($points_earned))); } // handle crediting points redeemed for a discount $points_redeemed = get_post_meta($order->id, '_wc_points_redeemed', true); if ($points_redeemed > 0) { // credit points WC_Points_Rewards_Manager::increase_points($order->user_id, $points_redeemed, 'order-cancelled', null, $order->id); // remove points from order delete_post_meta($order->id, '_wc_points_redeemed'); // add order note $order->add_order_note(sprintf(__('%d %s credited back to customer.', 'wc_points_rewards'), $points_redeemed, $wc_points_rewards->get_points_label($points_redeemed))); } }
/** * Add points to customer for creating an account * * @since 1.0 */ public function create_account_action($user_id) { $points = get_option('wc_points_rewards_account_signup_points'); if (!empty($points)) { WC_Points_Rewards_Manager::increase_points($user_id, $points, 'account-signup'); } }