Example #1
0
function swr_remove_reward($order_id)
{
    global $woocommerce, $swr_settings;
    $order = new WC_Order($order_id);
    if ($order->rewards_completed && $order->user_id > 0) {
        $swr_settings->set_reward_status_for_order($order_id, 0);
        $current_rewards = swr_get_user_current_rewards(array('user_id' => $order->user_id));
        if (!$current_rewards) {
            $current_rewards = 0;
        }
        $current_rewards -= $order->rewards_earned;
        update_user_meta($order->user_id, 'swr_rewards', $current_rewards);
        $reward = swr_clean_amount($swr_settings->format_reward($order->rewards_earned, true));
        $order->add_order_note(sprintf(__('Removed %s %s.', 'rewards'), $reward, $swr_settings->get_title()));
    }
}
 /**
  * Initialise Settings Form Fields
  */
 function init_form_fields()
 {
     $this->form_fields = array('swr_enable_rewards_system' => array('title' => __('Rewards system', 'woocommerce'), 'label' => __('Enable the Rewards system', 'woocommerce'), 'type' => 'checkbox', 'default' => 'no'), 'swr_rewards_title' => array('title' => __('Rewards title', 'woocommerce'), 'id' => 'swr_rewards_title', 'type' => 'text', 'tip' => __("The title to appear throughout your website. Ex.: Website's rewards", 'woocommerce')), 'swr_rewards_type' => array('title' => __('Rewards type', 'woocommerce'), 'id' => 'swr_rewards_type', 'tip' => __("The type of rewards you want to use. Money or points", 'woocommerce'), 'css' => 'width:150px;', 'type' => 'select', 'class' => 'chosen_select', 'options' => array('money' => __('Money', 'woocommerce'), 'points' => __('Points', 'woocommerce')), 'default' => 'money'), 'swr_rewards_calculation' => array('title' => __('Calculation type', 'woocommerce'), 'id' => 'swr_rewards_calculation', 'tip' => sprintf(__("How to calculate rewards.<br /><br />Percentage and point per currency: Will give a customer X%% of the order and calculate points based on how much a dollar is worth in points. Ex.: 3%% will give %s for an order of %s.<br /><br />Fraction and point value: Will give a customer X points per X amount spend and calculate value of points based on how much a point is worth. Ex.: 2/10 will give 2 points per %s.", 'woocommerce'), swr_clean_amount(woocommerce_price(0.45)), swr_clean_amount(woocommerce_price(15)), swr_clean_amount(woocommerce_price(10))), 'css' => 'width:250px;', 'type' => 'select', 'class' => 'chosen_select', 'options' => array('percentage' => __('Percentage', 'woocommerce'), 'fraction' => __('Fraction', 'woocommerce')), 'default' => 'percentage'), 'swr_rewards_percentage' => array('title' => __('Percentage', 'woocommerce'), 'description' => sprintf(__('Will give <span id="swr_percentage_value_enter">X</span> for an order of %s', 'woocommerce'), swr_clean_amount(woocommerce_price(10))), 'id' => 'swr_rewards_percentage', 'css' => 'width:40px;', 'type' => 'text', 'tip' => __('Percentage of rewards for each order. Ex.: 3%. You can add decimal too. Ex.: 2.75%', 'woocommerce')), 'swr_rewards_fraction' => array('title' => __('Fraction', 'woocommerce'), 'description' => sprintf(__(' Ex.: 1/10 will give 1 point for each %s spend, 3/20 will give 3 points for each %s spend.', 'woocommerce'), woocommerce_price(10), woocommerce_price(20)), 'id' => 'swr_rewards_fraction', 'css' => 'width:40px;', 'type' => 'text', 'desc_tip' => true), 'swr_rewards_fraction_type' => array('title' => __('Fraction type', 'woocommerce'), 'id' => 'swr_rewards_fraction_type', 'tip' => sprintf(__("The fraction type determine if a user should get partial points. Ex.: An order of %s with a fraction of 2/10 will give the customer 3.6 points in Loose, 3 in Loose with floor rounding, 2 in Strict.", 'woocommerce'), swr_clean_amount(woocommerce_price(18))), 'css' => 'width:250px;', 'type' => 'select', 'class' => 'chosen_select', 'options' => array('loose' => __('Loose', 'woocommerce'), 'loosefloor' => __('Loose with floor rounding', 'woocommerce'), 'strict' => __('Strict', 'woocommerce')), 'default' => 'loosefloor'), 'swr_rewards_used_type' => array('title' => __('How to use the rewards', 'woocommerce'), 'id' => 'swr_rewards_used_type', 'tip' => sprintf(__("Determine how the customer will use his rewards.<br /><br />Points value:<br />Will give the customer a choice to redeem his rewards has money in the cart.<br /><br />Specific product:<br />Only specified product can be bought with their points, you must enter a value in points for each product.", 'woocommerce'), swr_clean_amount(woocommerce_price(18))), 'css' => 'width:250px;', 'type' => 'select', 'class' => 'chosen_select', 'options' => array('pointsvalue' => __('Points value', 'woocommerce'), 'table' => __('Table of predefined points value', 'woocommerce')), 'default' => 'pointsvalue'), 'swr_rewards_points' => array('title' => __('Points per currency', 'woocommerce'), 'description' => sprintf(__('points = %s (Only used in Points)', 'woocommerce'), woocommerce_price(1)), 'id' => 'swr_rewards_points', 'css' => 'width:40px;', 'type' => 'text'), 'swr_rewards_points_value' => array('title' => __('Points value', 'woocommerce'), 'description' => sprintf(__('= 1 point', 'woocommerce'), woocommerce_price(1)), 'id' => 'swr_rewards_points_value', 'css' => 'width:40px;', 'type' => 'text'), 'swr_rewards_max_points' => array('title' => __('Maximum reward', 'woocommerce'), 'id' => 'swr_rewards_max_points', 'css' => 'width:40px;', 'type' => 'text', 'tip' => __('Maximum reward that a customer can receive for a single order. Leave empty if no limit.', 'woocommerce')), 'swr_rewards_min_points' => array('title' => __('Minimum cash in points', 'woocommerce'), 'id' => 'swr_rewards_min_points', 'css' => 'width:40px;', 'type' => 'text', 'tip' => __('Minimum points to be able to cash in. Ex.: 15 points minimum to let the customer use is points. Leave blank to let any points beeing used.', 'woocommerce')), 'table_values' => array('type' => 'table_values'), 'swr_apply_rewards_auto' => array('title' => __('Apply rewards auto', 'woocommerce'), 'type' => 'checkbox', 'default' => 'no', 'tip' => __('Will automatically apply the customer rewards in the checkout.', 'woocommerce')), 'swr_apply_rewards_to_rewards' => array('title' => __('Rewards to rewards', 'woocommerce'), 'type' => 'checkbox', 'default' => 'yes', 'tip' => sprintf(__('Give rewards to order that use rewards.<br /><br />Rewards to rewards checked:<br />An order of %s with a percentage of 2%% and customer used is bank of %s will give %s.<br /><br />Rewards to rewards not checked:<br />An order of %s with a percentage of 2%% and customer used is bank of %s will give %s.', 'woocommerce'), swr_clean_amount(woocommerce_price(10)), swr_clean_amount(woocommerce_price(5)), swr_clean_amount(woocommerce_price(0.2)), swr_clean_amount(woocommerce_price(10)), swr_clean_amount(woocommerce_price(5)), swr_clean_amount(woocommerce_price(0.1)))), 'swr_apply_rewards_to_shipping' => array('title' => __('Deduct shipping with rewards', 'woocommerce'), 'type' => 'checkbox', 'default' => 'yes', 'tip' => __('Use rewards value to deduct the shipping cost. If not enabled, the customer will always have to pay for shipping.', 'wc_rewards')), 'swr_apply_rewards_before_tax' => array('title' => __('Apply rewards before tax', 'woocommerce'), 'type' => 'checkbox', 'default' => 'no', 'tip' => __('Apply rewards money before tax', 'wc_rewards')), 'swr_apply_type' => array('title' => __('Where to apply the reward', 'woocommerce'), 'css' => 'max-width:250px;', 'type' => 'select', 'class' => 'chosen_select', 'options' => array('total' => __('Total', 'woocommerce'), 'subtotal' => __('Subtotal', 'woocommerce'), 'totalwithoutshipping' => __('Total without shipping', 'woocommerce')), 'default' => 'total', 'tip' => __('Select where to apply the rewards, from the total, subtotal or the total without shipping.', 'woocommerce')), 'swr_roles' => array('title' => __('Select roles that can use rewards', 'woocommerce'), 'css' => 'width:350px;', 'type' => 'multiselect', 'class' => 'chosen_select', 'options' => $this->roles, 'default' => $this->roles), 'paymentstitle' => array('title' => __('Payment gateways extra\'s', 'wc_rewards'), 'type' => 'title', 'description' => ''), 'payments' => array('type' => 'payment_gateways'), 'display' => array('title' => __('Display settings', 'wc_rewards'), 'type' => 'title', 'description' => ''), 'rewards_page' => array('title' => __('Rewards page description', 'wc_rewards'), 'default' => '', 'class' => 'chosen_select_nostd', 'css' => 'min-width:300px;', 'type' => 'single_select_page'), 'swr_cart_where_to_show' => array('title' => __('Where to show the rewards amount of the cart', 'woocommerce'), 'css' => 'width:350px;', 'type' => 'multiselect', 'class' => 'chosen_select', 'options' => array('topofcart' => __('Show on top of cart', 'woocommerce'), 'below_cart_table' => __('Show below the cart products table', 'woocommerce'), 'below_cart_totals' => __('Show below the cart totals', 'woocommerce'), 'below_shipping_calculator' => __('Show below the shipping calculator', 'woocommerce'), 'before_order' => __('Show before the order checkout form', 'woocommerce'), 'below_order' => __('Show below the order checkout form', 'woocommerce'), 'below_order_thankyou' => __('Show below the order thanks', 'woocommerce'), 'top_rewards' => __('Show on top of the rewards page', 'woocommerce'), 'below_product_price' => __('Show below single product price', 'woocommerce')), 'default' => array('topofcart', 'below_order', 'below_order_thankyou', 'top_rewards', 'below_product_price')), 'swr_use_rewards_where_to_show' => array('title' => __('"Use my rewards" location', 'woocommerce'), 'css' => 'width:350px;', 'type' => 'select', 'class' => 'chosen_select', 'options' => array('top' => __('Show on top of cart', 'woocommerce'), 'before' => __('Show on top of the cart products table', 'woocommerce'), 'after' => __('Show below the cart totals', 'woocommerce')), 'default' => 'before', 'tip' => __('Where to show the checkbox Use my rewards for this order on the checkout page.', 'woocommerce')), 'review' => array('title' => __('Reviews settings', 'wc_rewards'), 'type' => 'title', 'description' => ''), 'swr_enable_reviews_reward' => array('title' => __('Rewards review', 'woocommerce'), 'label' => __('Give rewards to customer when they review an item they bought', 'woocommerce'), 'type' => 'checkbox', 'default' => 'no'), 'swr_rewards_review_value' => array('title' => __('Rewards amount', 'woocommerce'), 'id' => 'swr_rewards_review_value', 'css' => 'width:40px;', 'type' => 'text', 'tip' => __('How much to give for a customer who review an item', 'woocommerce')), 'subscribe' => array('title' => __('Subscribe settings', 'wc_rewards'), 'type' => 'title', 'description' => ''), 'swr_enable_subscribe_reward' => array('title' => __('Rewards subscription', 'woocommerce'), 'label' => __('Give rewards to customer when they review an item they bought', 'woocommerce'), 'type' => 'checkbox', 'default' => 'no'), 'swr_rewards_subscribe_value' => array('title' => __('Rewards amount', 'woocommerce'), 'css' => 'width:40px;', 'type' => 'text', 'tip' => __('How much to give for a customer who subscribe to your website.', 'woocommerce')), 'text' => array('title' => __('Texts', 'wc_rewards'), 'type' => 'title', 'description' => ''), 'swr_no_rewards_text' => array('title' => __('Text no rewards', 'woocommerce'), 'css' => '', 'type' => 'text', 'tip' => __('Text that will be displayed when the order does not meet the minimum.', 'woocommerce')));
 }