Пример #1
0
 public function __construct()
 {
     parent::__construct();
     $options = FFLCommerce_Base::get_options();
     $this->id = 'local_pickup';
     $this->enabled = $options->get('fflcommerce_local_pickup_enabled');
     $this->title = $options->get('fflcommerce_local_pickup_title');
     $this->fee = $options->get('fflcommerce_local_pickup_handling_fee');
     $this->availability = $options->get('fflcommerce_local_pickup_availability');
     $this->countries = $options->get('fflcommerce_local_pickup_countries');
     $session = fflcommerce_session::instance();
     if (isset($session->chosen_shipping_method_id) && $session->chosen_shipping_method_id == $this->id) {
         $this->chosen = true;
     }
     add_action('fflcommerce_settings_scripts', array($this, 'admin_scripts'));
 }
Пример #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()));
}
 /**
  * remove the logged out user shipping information from the session once they log out
  *
  * @since 1.4.4
  */
 public function update_signed_out_customer()
 {
     unset(fflcommerce_session::instance()->customer);
     $this->set_default_customer();
 }
    function fflcommerce_product_customize_panel()
    {
        global $_product;
        if (isset($_POST['Submit']) && $_POST['Submit'] == __('Save Personalization', 'fflcommerce')) {
            $custom_products = (array) fflcommerce_session::instance()->customized_products;
            $custom_products[$_POST['customized_id']] = sanitize_text_field(stripslashes($_POST['fflcommerce_customized_product']));
            fflcommerce_session::instance()->customized_products = $custom_products;
        }
        if (get_post_meta($_product->ID, 'customizable', true) == 'yes') {
            $custom_products = (array) fflcommerce_session::instance()->customized_products;
            $custom = isset($custom_products[$_product->ID]) ? $custom_products[$_product->ID] : '';
            $custom_length = get_post_meta($_product->ID, 'customized_length', true);
            $length_str = $custom_length == '' ? '' : sprintf(__('You may enter a maximum of %s characters.', 'fflcommerce'), $custom_length);
            echo '<div class="panel" id="tab-customize">';
            echo '<p>' . apply_filters('fflcommerce_product_customize_heading', __('Enter your personal information as you want it to appear on the product.<br />', 'fflcommerce') . $length_str) . '</p>';
            ?>
			<form action="#" method="post">
				<input type="hidden" name="customized_id" value="<?php 
            echo esc_attr($_product->ID);
            ?>
" />
				<?php 
            if ($custom_length == '') {
                ?>
					<textarea id="fflcommerce_customized_product" name="fflcommerce_customized_product" cols="60" rows="4"><?php 
                echo esc_textarea($custom);
                ?>
</textarea>
				<?php 
            } else {
                ?>
					<input type="text" id="fflcommerce_customized_product" name="fflcommerce_customized_product" size="<?php 
                echo $custom_length;
                ?>
" maxlength="<?php 
                echo $custom_length;
                ?>
" value="<?php 
                echo esc_attr($custom);
                ?>
" />
				<?php 
            }
            ?>
				<p class="submit"><input name="Submit" type="submit" class="button-alt add_personalization" value="<?php 
            _e("Save Personalization", 'fflcommerce');
            ?>
" /></p>
			</form>
			<?php 
            echo '</div>';
        }
    }
 /**
  * Set the index to the selected service on the session (selected_rate_id)
  *
  * @param string $selected_service
  * @since 1.2
  */
 public function set_selected_service_index($selected_service = '')
 {
     if (!empty($selected_service)) {
         for ($i = 0; $i < $this->get_rates_amount(); $i++) {
             if ($this->get_selected_service($i) == $selected_service) {
                 fflcommerce_session::instance()->selected_rate_id = $i;
                 break;
             }
         }
     }
 }
 /**
  * Process the checkout after the confirm order button is pressed
  */
 public function process_checkout()
 {
     if (!defined('FFLCOMMERCE_CHECKOUT')) {
         define('FFLCOMMERCE_CHECKOUT', true);
     }
     // Initialize cart
     fflcommerce_cart::get_cart();
     fflcommerce_cart::calculate_totals();
     if (isset($_POST) && $_POST && !isset($_POST['login'])) {
         fflcommerce::verify_nonce('process_checkout');
         // this will fill in our $posted array with validated data
         self::validate_checkout();
         $gateway = fflcommerce_payment_gateways::get_gateway($this->posted['payment_method']);
         if (self::process_gateway($gateway)) {
             $gateway->validate_fields();
         }
         do_action('fflcommerce_after_checkout_validation', $this->posted, $_POST, sizeof(fflcommerce::$errors));
         if (fflcommerce::has_errors()) {
             return false;
         }
         if (!isset($_POST['update_totals'])) {
             $user_id = get_current_user_id();
             // Create customer account and log them in
             if ($this->show_signup && !$user_id && $this->posted['create_account']) {
                 $user_id = $this->create_user_account();
                 if ($user_id === 0) {
                     return false;
                 }
             }
             $billing = array('first_name' => $this->posted['billing_first_name'], 'last_name' => $this->posted['billing_last_name'], 'company' => $this->posted['billing_company'], 'address_1' => $this->posted['billing_address_1'], 'address_2' => $this->posted['billing_address_2'], 'city' => $this->posted['billing_city'], 'state' => $this->posted['billing_state'], 'postcode' => $this->posted['billing_postcode'], 'country' => $this->posted['billing_country'], 'phone' => $this->posted['billing_phone'], 'email' => $this->posted['billing_email']);
             fflcommerce_customer::set_country($billing['country']);
             fflcommerce_customer::set_state($billing['state']);
             fflcommerce_customer::set_postcode($billing['postcode']);
             if (isset($this->posted['billing_euvatno']) && $this->valid_euvatno) {
                 $billing['euvatno'] = $this->posted['billing_euvatno'];
                 $billing['euvatno'] = str_replace(' ', '', $billing['euvatno']);
                 // If country code is not provided - add one.
                 if (strpos($billing['euvatno'], $billing['country']) === false) {
                     $billing['euvatno'] = $billing['country'] . $billing['euvatno'];
                 }
             }
             // Get shipping/billing
             if (!empty($this->posted['shiptobilling'])) {
                 $shipping = $billing;
                 unset($shipping['phone'], $shipping['email']);
             } elseif (fflcommerce_shipping::is_enabled()) {
                 $shipping = array('first_name' => $this->posted['shipping_first_name'], 'last_name' => $this->posted['shipping_last_name'], 'company' => $this->posted['shipping_company'], 'address_1' => $this->posted['shipping_address_1'], 'address_2' => $this->posted['shipping_address_2'], 'city' => $this->posted['shipping_city'], 'state' => $this->posted['shipping_state'], 'postcode' => $this->posted['shipping_postcode'], 'country' => $this->posted['shipping_country']);
             }
             fflcommerce_customer::set_shipping_country($shipping['country']);
             fflcommerce_customer::set_shipping_state($shipping['state']);
             fflcommerce_customer::set_shipping_postcode($shipping['postcode']);
             // Update totals based on processed customer address
             fflcommerce_cart::calculate_totals();
             // Save billing/shipping to user meta fields
             if ($user_id > 0) {
                 foreach ($billing as $field => $value) {
                     update_user_meta($user_id, 'billing_' . $field, $value);
                 }
                 if (isset($shipping)) {
                     foreach ($shipping as $field => $value) {
                         update_user_meta($user_id, 'shipping_' . $field, $value);
                     }
                 }
             }
             if (!isset($_POST['submit_action']) || $_POST['submit_action'] != 'place_order') {
                 $result = fflcommerce::redirect(fflcommerce_get_page_id(FFLCOMMERCE_CHECKOUT));
                 return array('result' => 'redirect', 'redirect' => $result);
             }
             // Order meta data
             $data = array();
             $applied_coupons = array_map(function ($coupon) {
                 return JS_Coupons::get_coupon($coupon);
             }, fflcommerce_cart::get_coupons());
             do_action('fflcommerce_checkout_update_order_total', $this->posted);
             foreach ($billing as $field => $value) {
                 $data['billing_' . $field] = $value;
             }
             if (isset($shipping)) {
                 foreach ($shipping as $field => $value) {
                     $data['shipping_' . $field] = $value;
                 }
             }
             $data['order_discount_coupons'] = $applied_coupons;
             $data['shipping_method'] = $this->posted['shipping_method'];
             $data['shipping_service'] = $this->posted['shipping_service'];
             $data['payment_method'] = $this->posted['payment_method'];
             $data['payment_method_title'] = $gateway->title;
             $data['order_subtotal'] = fflcommerce_cart::get_subtotal();
             $data['order_discount_subtotal'] = fflcommerce_cart::get_discount_subtotal();
             $data['order_shipping'] = fflcommerce_cart::get_shipping_total();
             $data['order_discount'] = fflcommerce_cart::get_total_discount(false);
             $data['order_tax'] = fflcommerce_cart::get_taxes_as_string();
             $data['order_tax_no_shipping_tax'] = fflcommerce_cart::get_total_cart_tax_without_shipping_tax();
             $data['order_tax_divisor'] = fflcommerce_cart::get_tax_divisor();
             $data['order_shipping_tax'] = fflcommerce_cart::get_shipping_tax();
             $data['order_total'] = fflcommerce_cart::get_total(false);
             $data['order_total_prices_per_tax_class_ex_tax'] = fflcommerce_cart::get_price_per_tax_class_ex_tax();
             if ($this->valid_euvatno) {
                 $data['order_tax'] = '';
                 $temp = fflcommerce_cart::get_total_cart_tax_without_shipping_tax();
                 $data['order_total'] -= $data['order_shipping_tax'] + $temp;
                 $data['order_shipping_tax'] = 0;
             }
             // Cart items
             $order_items = array();
             foreach (fflcommerce_cart::get_cart() as $values) {
                 /** @var fflcommerce_product $product */
                 $product = $values['data'];
                 // Check stock levels
                 if (!$product->has_enough_stock($values['quantity'])) {
                     fflcommerce::add_error(sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. Please edit your cart and try again. We apologize for any inconvenience caused.', 'fflcommerce'), $product->get_title()));
                     if (self::get_options()->get('fflcommerce_show_stock') == 'yes') {
                         fflcommerce::add_error(sprintf(__('We have only %d available at this time.', 'fflcommerce'), $product->get_stock()));
                     }
                     break;
                 }
                 // Calc item tax to store
                 $rates = $product->get_tax_destination_rate();
                 $rates = current($rates);
                 if (isset($rates['rate'])) {
                     $rate = $rates['rate'];
                 } else {
                     $rate = 0.0;
                 }
                 if ($this->valid_euvatno) {
                     $rate = 0.0;
                 }
                 $price_inc_tax = $product->get_price_with_tax();
                 if (!empty($values['variation_id'])) {
                     $product_id = $values['variation_id'];
                 } else {
                     $product_id = $values['product_id'];
                 }
                 $custom_products = (array) fflcommerce_session::instance()->customized_products;
                 $custom = isset($custom_products[$product_id]) ? $custom_products[$product_id] : '';
                 if (!empty($custom)) {
                     unset($custom_products[$product_id]);
                     fflcommerce_session::instance()->customized_products = $custom_products;
                 }
                 $order_items[] = apply_filters('new_order_item', array('id' => $values['product_id'], 'variation_id' => $values['variation_id'], 'variation' => $values['variation'], 'customization' => $custom, 'name' => $product->get_title(), 'qty' => (int) $values['quantity'], 'cost' => $product->get_price_excluding_tax(), 'cost_inc_tax' => $price_inc_tax, 'taxrate' => $rate), $values);
             }
             if (fflcommerce::has_errors()) {
                 return false;
             }
             // Insert or update the post data
             $create_new_order = true;
             $order_data = array('post_type' => 'shop_order', 'post_title' => 'Order &ndash; ' . date('F j, Y @ h:i A'), 'post_status' => 'publish', 'post_excerpt' => $this->posted['order_comments'], 'post_author' => 1);
             $order_id = 0;
             if (isset(fflcommerce_session::instance()->order_awaiting_payment) && fflcommerce_session::instance()->order_awaiting_payment > 0) {
                 $order_id = absint(fflcommerce_session::instance()->order_awaiting_payment);
                 $terms = wp_get_object_terms($order_id, 'shop_order_status', array('fields' => 'slugs'));
                 $order_status = isset($terms[0]) ? $terms[0] : 'pending';
                 // Resume the unpaid order if its pending
                 if ($order_status == 'pending' || $order_status == 'failed') {
                     $create_new_order = false;
                     $order_data['ID'] = $order_id;
                     wp_update_post($order_data);
                 }
             }
             if ($create_new_order) {
                 $order_id = wp_insert_post($order_data);
             }
             if (is_wp_error($order_id) || $order_id === 0) {
                 fflcommerce::add_error(__('Error: Unable to create order. Please try again.', 'fflcommerce'));
                 return false;
             }
             // Update post meta
             update_post_meta($order_id, 'order_data', $data);
             update_post_meta($order_id, 'order_key', uniqid('order_'));
             update_post_meta($order_id, 'customer_user', (int) $user_id);
             update_post_meta($order_id, 'order_items', $order_items);
             wp_set_object_terms($order_id, 'pending', 'shop_order_status');
             $order = new fflcommerce_order($order_id);
             /* Coupon usage limit */
             foreach ($data['order_discount_coupons'] as $coupon) {
                 $coupon_id = JS_Coupons::get_coupon_post_id($coupon['code']);
                 if ($coupon_id !== false) {
                     $usage_count = get_post_meta($coupon_id, 'usage', true);
                     $usage_count = empty($usage_count) ? 1 : $usage_count + 1;
                     update_post_meta($coupon_id, 'usage', $usage_count);
                 }
             }
             if ($create_new_order) {
                 do_action('fflcommerce_new_order', $order_id);
             } else {
                 do_action('fflcommerce_resume_order', $order_id);
             }
             do_action('fflcommerce_checkout_update_order_meta', $order_id, $this->posted);
             // can't just simply check needs_payment() here, as paypal may have force payment set to true
             if (self::process_gateway($gateway)) {
                 // Store Order ID in session so it can be re-used after payment failure
                 fflcommerce_session::instance()->order_awaiting_payment = $order_id;
                 // Process Payment
                 $result = $gateway->process_payment($order_id);
                 // Redirect to success/confirmation/payment page
                 if ($result['result'] == 'success') {
                     return $result;
                 }
                 return false;
             } else {
                 // No payment was required for order
                 $order->payment_complete();
                 // Empty the Cart
                 fflcommerce_cart::empty_cart();
                 // Redirect to success/confirmation/payment page
                 $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks'));
                 return array('result' => 'redirect', 'redirect' => $checkout_redirect);
             }
         }
     }
     return true;
 }
Пример #7
0
            ?>
">
								<?php 
            echo apply_filters('fflcommerce_cart_product_title', $product->get_title(), $product);
            ?>
							</a>
							<?php 
            echo $additional_description;
            ?>
							<?php 
            if (!empty($values['variation_id'])) {
                $product_id = $values['variation_id'];
            } else {
                $product_id = $values['product_id'];
            }
            $custom_products = (array) fflcommerce_session::instance()->customized_products;
            $custom = isset($custom_products[$product_id]) ? $custom_products[$product_id] : '';
            if (!empty($custom_products[$product_id])) {
                ?>
								<dl class="customization">
									<dt class="customized_product_label"><?php 
                echo apply_filters('fflcommerce_customized_product_label', __('Personal: ', 'fflcommerce'));
                ?>
</dt>
									<dd class="customized_product"><?php 
                echo esc_textarea($custom);
                ?>
</dd>
								</dl>
							<?php 
            }
Пример #8
0
 /**
  * Logs viewed products into the session
  *
  * @var $post WP_Post
  * @var $_product fflcommerce_product
  * @return void
  **/
 public function fflcommerce_product_view_tracker($post, $_product)
 {
     $instance = get_option('widget_recently_viewed_products');
     $number = 0;
     if (!empty($instance)) {
         foreach ($instance as $index => $entry) {
             if (is_array($entry)) {
                 foreach ($entry as $key => $value) {
                     if ($key == 'number') {
                         $number = $value;
                         break;
                     }
                 }
             }
         }
     }
     if (!$number) {
         return false;
     }
     // stop the show!
     // Check if we already have some data
     if (!is_array(fflcommerce_session::instance()->recently_viewed_products)) {
         $viewed = array();
         fflcommerce_session::instance()->recently_viewed_products = $viewed;
     }
     // If the product isn't in the list, add it
     if (!in_array($post->ID, fflcommerce_session::instance()->recently_viewed_products)) {
         $viewed = fflcommerce_session::instance()->recently_viewed_products;
         $viewed[] = $post->ID;
         fflcommerce_session::instance()->recently_viewed_products = $viewed;
     }
     if (sizeof(fflcommerce_session::instance()->recently_viewed_products) > $number) {
         $viewed = fflcommerce_session::instance()->recently_viewed_products;
         array_shift($viewed);
         fflcommerce_session::instance()->recently_viewed_products = $viewed;
     }
 }
 /**
  * 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;
 }
Пример #10
0
function fflcommerce_frontend_scripts()
{
    $options = FFLCommerce_Base::get_options();
    $frontend_css = FFLCOMMERCE_URL . '/assets/css/frontend.css';
    $theme_css = file_exists(get_stylesheet_directory() . '/fflcommerce/style.css') ? get_stylesheet_directory_uri() . '/fflcommerce/style.css' : $frontend_css;
    if ($options->get('fflcommerce_disable_css') == 'no') {
        if ($options->get('fflcommerce_frontend_with_theme_css') == 'yes' && $frontend_css != $theme_css) {
            jrto_enqueue_style('frontend', 'fflcommerce_theme_styles', $frontend_css);
        }
        jrto_enqueue_style('frontend', 'fflcommerce_styles', $theme_css);
    }
    wp_enqueue_script('jquery');
    wp_register_script('jquery-blockui', '//cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.66.0-2013.10.09/jquery.blockUI.min.js', array('jquery'), '2.66.0');
    wp_enqueue_script('jquery-blockui');
    jrto_enqueue_script('frontend', 'fflcommerce_global', FFLCOMMERCE_URL . '/assets/js/global.js', array('jquery'), array('in_footer' => true));
    if ($options->get('fflcommerce_disable_fancybox') == 'no') {
        jrto_enqueue_script('frontend', 'prettyPhoto', FFLCOMMERCE_URL . '/assets/js/jquery.prettyPhoto.js', array('jquery'), array('in_footer' => true));
        jrto_enqueue_style('frontend', 'prettyPhoto', FFLCOMMERCE_URL . '/assets/css/prettyPhoto.css');
    }
    jrto_enqueue_script('frontend', 'fflcommerce-cart', FFLCOMMERCE_URL . '/assets/js/cart.js', array('jquery'), array('in_footer' => true, 'page' => FFLCOMMERCE_CART));
    jrto_enqueue_script('frontend', 'fflcommerce-checkout', FFLCOMMERCE_URL . '/assets/js/checkout.js', array('jquery', 'jquery-blockui'), array('in_footer' => true, 'page' => array(FFLCOMMERCE_CHECKOUT, FFLCOMMERCE_PAY)));
    jrto_enqueue_script('frontend', 'fflcommerce-validation', FFLCOMMERCE_URL . '/assets/js/validation.js', array(), array('in_footer' => true, 'page' => FFLCOMMERCE_CHECKOUT));
    jrto_enqueue_script('frontend', 'fflcommerce-payment', FFLCOMMERCE_URL . '/assets/js/pay.js', array('jquery'), array('page' => FFLCOMMERCE_PAY));
    jrto_enqueue_script('frontend', 'fflcommerce-single-product', FFLCOMMERCE_URL . '/assets/js/single-product.js', array('jquery'), array('in_footer' => true, 'page' => FFLCOMMERCE_PRODUCT));
    jrto_enqueue_script('frontend', 'fflcommerce-countries', FFLCOMMERCE_URL . '/assets/js/countries.js', array(), array('in_footer' => true, 'page' => array(FFLCOMMERCE_CHECKOUT, FFLCOMMERCE_CART, FFLCOMMERCE_EDIT_ADDRESS)));
    /* Script.js variables */
    // TODO: clean this up, a lot aren't even used anymore, do away with it
    $fflcommerce_params = array('ajax_url' => admin_url('admin-ajax.php', 'fflcommerce'), 'assets_url' => FFLCOMMERCE_URL, 'validate_postcode' => $options->get('fflcommerce_enable_postcode_validating', 'no'), 'checkout_url' => admin_url('admin-ajax.php?action=fflcommerce-checkout', 'fflcommerce'), 'currency_symbol' => get_fflcommerce_currency_symbol(), 'get_variation_nonce' => wp_create_nonce("get-variation"), 'load_fancybox' => $options->get('fflcommerce_disable_fancybox') == 'no', 'option_guest_checkout' => $options->get('fflcommerce_enable_guest_checkout'), 'select_state_text' => __('Select a state&hellip;', 'fflcommerce'), 'state_text' => __('state', 'fflcommerce'), 'ratings_message' => __('Please select a star to rate your review.', 'fflcommerce'), 'update_order_review_nonce' => wp_create_nonce("update-order-review"), 'billing_state' => fflcommerce_customer::get_state(), 'shipping_state' => fflcommerce_customer::get_shipping_state(), 'is_checkout' => is_page(fflcommerce_get_page_id('checkout')) || is_page(fflcommerce_get_page_id('pay')), 'error_hide_time' => FFLCommerce_Base::get_options()->get('fflcommerce_error_disappear_time', 8000), 'message_hide_time' => FFLCommerce_Base::get_options()->get('fflcommerce_message_disappear_time', 4000));
    if (isset(fflcommerce_session::instance()->min_price)) {
        $fflcommerce_params['min_price'] = $_GET['min_price'];
    }
    if (isset(fflcommerce_session::instance()->max_price)) {
        $fflcommerce_params['max_price'] = $_GET['max_price'];
    }
    $fflcommerce_params = apply_filters('fflcommerce_params', $fflcommerce_params);
    jrto_localize_script('fflcommerce_global', 'fflcommerce_params', $fflcommerce_params);
}
Пример #11
0
function fflcommerce_clear_cart_after_payment($url = false)
{
    if (isset(fflcommerce_session::instance()->order_awaiting_payment) && fflcommerce_session::instance()->order_awaiting_payment > 0) {
        $order = new fflcommerce_order(fflcommerce_session::instance()->order_awaiting_payment);
        if ($order->id > 0 && ($order->status == 'completed' || $order->status == 'processing')) {
            fflcommerce_cart::empty_cart();
            unset(fflcommerce_session::instance()->order_awaiting_payment);
        }
    }
}
Пример #12
0
 /**
  * Redirection hook which stores messages into session data
  *
  * @param $location
  * @param $status
  * @return string Location
  */
 public static function redirect($location, $status = null)
 {
     fflcommerce_session::instance()->errors = self::$errors;
     fflcommerce_session::instance()->messages = self::$messages;
     return apply_filters('fflcommerce_session_location_filter', $location);
 }
Пример #13
0
 public function fflcommerce_price_filter_init()
 {
     // if price filter in use on front end, load jquery-ui slider (WP loads in footer)
     if (is_active_widget(false, false, 'fflcommerce_price_filter', true) && !is_admin()) {
         wp_enqueue_script('jquery-ui-slider');
     }
     unset(fflcommerce_session::instance()->min_price);
     unset(fflcommerce_session::instance()->max_price);
     if (isset($_GET['min_price'])) {
         fflcommerce_session::instance()->min_price = $_GET['min_price'];
     }
     if (isset($_GET['max_price'])) {
         fflcommerce_session::instance()->max_price = $_GET['max_price'];
     }
 }
 public static function remove_coupon($code)
 {
     if (!is_array(fflcommerce_session::instance()->coupons)) {
         return false;
     }
     /* Loop to find the key of this coupon */
     foreach (fflcommerce_session::instance()->coupons as $key => $coupon) {
         if ($code == $coupon) {
             unset(fflcommerce_cart::$applied_coupons[$key]);
             $data = (array) fflcommerce_session::instance()->coupons;
             unset($data[$key]);
             fflcommerce_session::instance()->coupons = $data;
             return true;
         }
     }
 }
 /**
  * Calculate the shipping price
  *
  * @param $tax fflcommerce_tax The tax
  */
 public static function calculate_shipping($tax)
 {
     if (self::$enabled == 'yes') {
         self::reset_shipping_methods();
         self::reset_shipping();
         // do not reset session (chosen_shipping_method_id)
         $calc_cheapest = false;
         if (!empty(fflcommerce_session::instance()->chosen_shipping_method_id)) {
             $chosen_method = fflcommerce_session::instance()->chosen_shipping_method_id;
         } else {
             $chosen_method = '';
             $calc_cheapest = true;
         }
         $_available_methods = self::get_available_shipping_methods();
         if (sizeof($_available_methods) > 0) {
             // have to check numeric selected_rate_id because it can be 0, and empty returns true for 0. That is unwanted behaviour
             if (is_numeric(fflcommerce_session::instance()->selected_rate_id) && !empty($chosen_method)) {
                 //make sure all methods are re-calculated since prices have been reset. Otherwise the other shipping
                 //method prices will show free
                 foreach ($_available_methods as $method) {
                     $method->set_tax($tax);
                     $method->calculate_shipping();
                 }
                 // select chosen method.
                 if (isset($_available_methods[$chosen_method]) && $_available_methods[$chosen_method] && !$_available_methods[$chosen_method]->has_error()) {
                     $chosen_method = $_available_methods[$chosen_method]->id;
                     // chosen shipping method had issues, need to auto calculate cheapest method now
                 } else {
                     $chosen_method = self::get_cheapest_method($_available_methods, $tax);
                 }
             } else {
                 // current fflcommerce functionality
                 $_cheapest_method = self::get_cheapest_method($_available_methods, $tax);
                 if (!$_cheapest_method) {
                     // there was an error, and if chosen method was in the session we want to reset that
                     $chosen_method = $_cheapest_method;
                 } else {
                     if ($calc_cheapest || !isset($_available_methods[$chosen_method])) {
                         $chosen_method = $_cheapest_method;
                     }
                 }
             }
             if ($chosen_method) {
                 //sets session in the method choose()
                 $_available_methods[$chosen_method]->choose();
                 self::$shipping_total = $_available_methods[$chosen_method]->get_selected_price(fflcommerce_session::instance()->selected_rate_id);
                 self::$shipping_tax = $_available_methods[$chosen_method]->get_selected_tax(fflcommerce_session::instance()->selected_rate_id);
                 self::$shipping_label = $_available_methods[$chosen_method]->get_selected_service(fflcommerce_session::instance()->selected_rate_id);
             }
         }
         //sizeof available methods
     }
     //self enabled == 'yes'
 }
 /**
  * When a payment is complete this function is called
  * Most of the time this should mark an order as 'processing' so that admin can process/post the items
  * If the cart contains only downloadable items then the order is 'complete' since the admin needs to take no action
  * Stock levels are reduced at this point
  */
 public function payment_complete()
 {
     unset(fflcommerce_session::instance()->order_awaiting_payment);
     $downloadable_order = false;
     if (sizeof($this->items) > 0) {
         foreach ($this->items as $item) {
             if ($item['id'] > 0) {
                 $_product = $this->get_product_from_item($item);
                 if ($_product->is_type('downloadable') || $_product->is_type('virtual')) {
                     $downloadable_order = true;
                     continue;
                 }
             }
             $downloadable_order = false;
             break;
         }
     }
     if ($downloadable_order) {
         $this->update_status('completed');
     } else {
         $this->update_status('processing');
     }
     // Payment is complete so reduce stock levels
     $this->reduce_order_stock();
     // Add the sale
     $this->add_sale();
     do_action('fflcommerce_payment_complete', $this->id);
 }