Esempio n. 1
0
/**
 * My Orders
 *
 * Shows recent orders on the account page
 */
global $woocommerce, $recent_orders, $swr_settings, $swr_refer;
$customer_id = get_current_user_id();
if ($swr_settings->current_user_can_use_rewards()) {
    if (version_compare($woocommerce->version, '2.2.0') >= 0) {
        $args = array('numberposts' => $recent_orders, 'meta_key' => '_customer_user', 'meta_value' => $customer_id, 'post_type' => 'shop_order', 'post_status' => array_keys(wc_get_order_statuses()));
    } else {
        $args = array('numberposts' => $recent_orders, 'meta_key' => '_customer_user', 'meta_value' => $customer_id, 'post_type' => 'shop_order', 'post_status' => 'publish');
    }
    $customer_orders = get_posts($args);
    $msg = sprintf(__('Current %s balance: %s', 'rewards'), $swr_settings->get_title(), swr_get_user_current_rewards(array('user_id' => $customer_id, 'formatted' => true)));
    ?>

<?php 
    if ($swr_settings->show_top_rewards()) {
        ?>
<p class="<?php 
        echo WOOCOMMERCE_VERSION >= 2 ? 'woocommerce-info' : 'woocommerce_info';
        ?>
 swr_get_rewards"><?php 
        echo $msg;
        ?>
</p>
<?php 
    }
    ?>
Esempio n. 2
0
/**
 * Define values for custom columns.
 *
 * @access public
 * @param mixed $value The value of the column being displayed
 * @param mixed $column_name The name of the column being displayed
 * @param mixed $user_id The ID of the user being displayed
 * @return string Value for the column
 */
function swr_user_column_values($value, $column_name, $user_id)
{
    global $woocommerce, $wpdb, $swr_settings;
    switch ($column_name) {
        case "swr_rewards_balance":
            $value = swr_get_user_current_rewards(array('user_id' => $user_id, 'formatted' => true)) . ' ' . $swr_settings->get_title();
            break;
    }
    return $value;
}
 public function give_back_rewards_for_order($order_id)
 {
     $order = new WC_Order($order_id);
     $current_rewards_non = swr_get_user_current_rewards(array('user_id' => $order->user_id));
     if ($order->rewards_used > 0) {
         $this->set_user_rewards($order->user_id, $current_rewards_non + $order->rewards_used);
     }
 }