Beispiel #1
0
function fflcommerce_checkout($atts)
{
    if (!defined('FFLCOMMERCE_CHECKOUT')) {
        define('FFLCOMMERCE_CHECKOUT', true);
    }
    $non_js_checkout = isset($_POST['update_totals']) && $_POST['update_totals'] ? true : false;
    $result = fflcommerce_cart::check_cart_item_stock();
    if (is_wp_error($result)) {
        fflcommerce::add_error($result->get_error_message());
    }
    if (!fflcommerce::has_errors() && $non_js_checkout) {
        fflcommerce::add_message(__('The order totals have been updated. Please confirm your order by pressing the Place Order button at the bottom of the page.', 'fflcommerce'));
    }
    fflcommerce::show_messages();
    fflcommerce_get_template('checkout/form.php', false);
}
Beispiel #2
0
function fflcommerce_cart($atts)
{
    unset(fflcommerce_session::instance()->selected_rate_id);
    // Process Discount Codes
    if (isset($_POST['apply_coupon']) && $_POST['apply_coupon'] && fflcommerce::verify_nonce('cart')) {
        $coupon_code = sanitize_title($_POST['coupon_code']);
        fflcommerce_cart::add_discount($coupon_code);
    } elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && fflcommerce::verify_nonce('cart')) {
        // Update Shipping
        unset(fflcommerce_session::instance()->chosen_shipping_method_id);
        $country = $_POST['calc_shipping_country'];
        $state = $_POST['calc_shipping_state'];
        $postcode = $_POST['calc_shipping_postcode'];
        if ($postcode && !fflcommerce_validation::is_postcode($postcode, $country)) {
            fflcommerce::add_error(__('Please enter a valid postcode/ZIP.', 'fflcommerce'));
            $postcode = '';
        } elseif ($postcode) {
            $postcode = fflcommerce_validation::format_postcode($postcode, $country);
        }
        if ($country) {
            // Update customer location
            fflcommerce_customer::set_location($country, $state, $postcode);
            fflcommerce_customer::set_shipping_location($country, $state, $postcode);
            fflcommerce::add_message(__('Shipping costs updated.', 'fflcommerce'));
        } else {
            fflcommerce_customer::set_shipping_location('', '', '');
            fflcommerce::add_message(__('Shipping costs updated.', 'fflcommerce'));
        }
    } elseif (isset($_POST['shipping_rates'])) {
        $rates_params = explode(":", $_POST['shipping_rates']);
        $available_methods = fflcommerce_shipping::get_available_shipping_methods();
        $shipping_method = $available_methods[$rates_params[0]];
        if ($rates_params[1] != null) {
            fflcommerce_session::instance()->selected_rate_id = $rates_params[1];
        }
        $shipping_method->choose();
        // chooses the method selected by user.
    }
    // Re-Calc prices. This needs to happen every time the cart page is loaded and after checking post results.
    fflcommerce_cart::calculate_totals();
    $result = fflcommerce_cart::check_cart_item_stock();
    if (is_wp_error($result)) {
        fflcommerce::add_error($result->get_error_message());
    }
    fflcommerce_render('shortcode/cart', array('cart' => fflcommerce_cart::get_cart(), 'coupons' => fflcommerce_cart::get_coupons()));
}
Beispiel #3
0
        exit;
    }
    if ($isViewOrder) {
        if (!isset($_GET['order'])) {
            wp_safe_redirect(apply_filters('fflcommerce_get_myaccount_page_id', get_permalink(fflcommerce_get_page_id('myaccount'))));
            exit;
        }
        $order = new fflcommerce_order($_GET['order']);
        if ($order->user_id != get_current_user_id()) {
            wp_safe_redirect(apply_filters('fflcommerce_get_myaccount_page_id', get_permalink(fflcommerce_get_page_id('myaccount'))));
            exit;
        }
    }
    if ($isChangePassword) {
        $user_id = get_current_user_id();
        if ($_POST && $user_id > 0 && fflcommerce::verify_nonce('change_password')) {
            if ($_POST['password-1'] && $_POST['password-2']) {
                if ($_POST['password-1'] == $_POST['password-2']) {
                    wp_update_user(array('ID' => $user_id, 'user_pass' => $_POST['password-1']));
                    fflcommerce::add_message(__('Password changed successfully.', 'fflcommerce'));
                    wp_safe_redirect(apply_filters('fflcommerce_get_myaccount_page_id', get_permalink(fflcommerce_get_page_id(FFLCOMMERCE_MY_ACCOUNT))));
                    exit;
                } else {
                    fflcommerce::add_error(__('Passwords do not match.', 'fflcommerce'));
                }
            } else {
                fflcommerce::add_error(__('Please enter your password.', 'fflcommerce'));
            }
        }
    }
});
 /**
  * Applies a coupon code
  *
  * @param string $coupon_code The code to apply
  * @return bool True if the coupon is applied, false if it does not exist or cannot be applied
  */
 public static function add_discount($coupon_code)
 {
     if (!self::is_valid_coupon($coupon_code)) {
         return false;
     }
     // Check for other individual_use coupons before adding this coupon.
     foreach (self::get_coupons() as $code) {
         $current = JS_Coupons::get_coupon($code);
         if ($current['individual_use']) {
             fflcommerce::add_error(__("There is already an 'individual use' coupon on the Cart.  No other coupons can be added until it is removed.", 'fflcommerce'));
             return false;
         }
     }
     $coupon = JS_Coupons::get_coupon($coupon_code);
     // Remove other coupons if this one is individual_use.
     if ($coupon['individual_use']) {
         if (!empty(self::$applied_coupons)) {
             fflcommerce::add_error(__("This is an 'individual use' coupon.  All other discount coupons have been removed.", 'fflcommerce'));
             self::$applied_coupons = array();
         }
     }
     // check if coupon is already applied and only add a new coupon
     if (!self::has_discount($coupon_code) && !empty($_POST['coupon_code'])) {
         self::$applied_coupons[] = $coupon_code;
     }
     fflcommerce_session::instance()->coupons = self::$applied_coupons;
     fflcommerce::add_message(__('Discount coupon applied successfully.', 'fflcommerce'));
     return true;
 }
function fflcommerce_cancel_order()
{
    if (isset($_GET['cancel_order']) && isset($_GET['order']) && isset($_GET['order_id'])) {
        $order_key = urldecode($_GET['order']);
        $order_id = (int) $_GET['order_id'];
        $order = new fflcommerce_order($order_id);
        if ($order->id == $order_id && $order->order_key == $order_key && $order->status == 'pending' && fflcommerce::verify_nonce('cancel_order')) {
            // Cancel the order + restore stock
            $order->cancel_order(__('Order cancelled by customer.', 'fflcommerce'));
            // Message
            fflcommerce::add_message(__('Your order was cancelled.', 'fflcommerce'));
        } elseif ($order->status != 'pending') {
            fflcommerce::add_error(__('Your order is no longer pending and could not be cancelled. Please contact us if you need assistance.', 'fflcommerce'));
        } else {
            fflcommerce::add_error(__('Invalid order.', 'fflcommerce'));
        }
        wp_safe_redirect(fflcommerce_cart::get_cart_url());
        exit;
    }
}