/**
  * Add Menu Cart to menu
  * 
  * @return menu items including cart
  */
 public function submenu_items()
 {
     $get_cart = jigoshop_cart::get_cart();
     $submenu_items = '';
     //see jigoshop/widgets/cart.php
     if (count($get_cart) > 0) {
         foreach ($get_cart as $cart_item_key => $values) {
             $_product = $values['data'];
             if ($_product->exists() && $values['quantity'] > 0) {
                 $item_thumbnail = has_post_thumbnail($_product->id) ? get_the_post_thumbnail($_product->id, 'shop_tiny') : jigoshop_get_image_placeholder('shop_tiny');
                 $item_name = $_product->get_title();
                 // Not used: Displays variations and cart item meta
                 $item_meta = jigoshop_cart::get_item_data($values);
                 $item_quantity = esc_attr($values['quantity']);
                 $item_price = $_product->get_price_html();
                 // Item permalink
                 $item_permalink = esc_attr(get_permalink($_product->id));
                 $submenu_items[] = array('item_thumbnail' => $item_thumbnail, 'item_name' => $item_name, 'item_quantity' => $item_quantity, 'item_price' => $item_price, 'item_permalink' => $item_permalink);
             }
         }
     } else {
         $submenu_items = '';
     }
     return $submenu_items;
 }
示例#2
0
function jigoshop_cart($atts)
{
    unset(jigoshop_session::instance()->selected_rate_id);
    // Process Discount Codes
    if (isset($_POST['apply_coupon']) && $_POST['apply_coupon'] && jigoshop::verify_nonce('cart')) {
        $coupon_code = sanitize_title($_POST['coupon_code']);
        jigoshop_cart::add_discount($coupon_code);
    } elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && jigoshop::verify_nonce('cart')) {
        // Update Shipping
        unset(jigoshop_session::instance()->chosen_shipping_method_id);
        $country = $_POST['calc_shipping_country'];
        $state = $_POST['calc_shipping_state'];
        $postcode = $_POST['calc_shipping_postcode'];
        if ($postcode && !jigoshop_validation::is_postcode($postcode, $country)) {
            jigoshop::add_error(__('Please enter a valid postcode/ZIP.', 'jigoshop'));
            $postcode = '';
        } elseif ($postcode) {
            $postcode = jigoshop_validation::format_postcode($postcode, $country);
        }
        if ($country) {
            // Update customer location
            jigoshop_customer::set_location($country, $state, $postcode);
            jigoshop_customer::set_shipping_location($country, $state, $postcode);
            jigoshop::add_message(__('Shipping costs updated.', 'jigoshop'));
        } else {
            jigoshop_customer::set_shipping_location('', '', '');
            jigoshop::add_message(__('Shipping costs updated.', 'jigoshop'));
        }
    } elseif (isset($_POST['shipping_rates'])) {
        $rates_params = explode(":", $_POST['shipping_rates']);
        $available_methods = jigoshop_shipping::get_available_shipping_methods();
        $shipping_method = $available_methods[$rates_params[0]];
        if ($rates_params[1] != null) {
            jigoshop_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.
    jigoshop_cart::calculate_totals();
    $result = jigoshop_cart::check_cart_item_stock();
    if (is_wp_error($result)) {
        jigoshop::add_error($result->get_error_message());
    }
    jigoshop_render('shortcode/cart', array('cart' => jigoshop_cart::get_cart(), 'coupons' => jigoshop_cart::get_coupons()));
}
示例#3
0
function jigoshop_process_checkout()
{
    if (!is_checkout() || is_jigoshop_single_page(JIGOSHOP_PAY)) {
        return;
    }
    if (count(jigoshop_cart::get_cart()) == 0) {
        wp_safe_redirect(get_permalink(jigoshop_get_page_id('cart')));
        exit;
    }
    /** @var jigoshop_checkout $_checkout */
    $_checkout = jigoshop_checkout::instance();
    $result = $_checkout->process_checkout();
    if (isset($result['result']) && $result['result'] === 'success') {
        wp_safe_redirect(apply_filters('jigoshop_is_ajax_payment_successful', $result['redirect']));
        exit;
    }
    if (isset($result['redirect'])) {
        wp_safe_redirect(get_permalink($result['redirect']));
        exit;
    }
}
 /**
  * Process the checkout after the confirm order button is pressed
  */
 public function process_checkout()
 {
     if (!defined('JIGOSHOP_CHECKOUT')) {
         define('JIGOSHOP_CHECKOUT', true);
     }
     // Initialize cart
     jigoshop_cart::get_cart();
     jigoshop_cart::calculate_totals();
     if (isset($_POST) && $_POST && !isset($_POST['login'])) {
         jigoshop::verify_nonce('process_checkout');
         // this will fill in our $posted array with validated data
         self::validate_checkout();
         $gateway = jigoshop_payment_gateways::get_gateway($this->posted['payment_method']);
         if (self::process_gateway($gateway)) {
             $gateway->validate_fields();
         }
         do_action('jigoshop_after_checkout_validation', $this->posted, $_POST, sizeof(jigoshop::$errors));
         if (jigoshop::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']);
             jigoshop_customer::set_country($billing['country']);
             jigoshop_customer::set_state($billing['state']);
             jigoshop_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 (jigoshop_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']);
             }
             jigoshop_customer::set_shipping_country($shipping['country']);
             jigoshop_customer::set_shipping_state($shipping['state']);
             jigoshop_customer::set_shipping_postcode($shipping['postcode']);
             // Update totals based on processed customer address
             jigoshop_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 = jigoshop::redirect(jigoshop_get_page_id(JIGOSHOP_CHECKOUT));
                 return array('result' => 'redirect', 'redirect' => $result);
             }
             // Order meta data
             $data = array();
             $applied_coupons = array_map(function ($coupon) {
                 return JS_Coupons::get_coupon($coupon);
             }, jigoshop_cart::get_coupons());
             do_action('jigoshop_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'] = jigoshop_cart::get_subtotal();
             $data['order_discount_subtotal'] = jigoshop_cart::get_discount_subtotal();
             $data['order_shipping'] = jigoshop_cart::get_shipping_total();
             $data['order_discount'] = jigoshop_cart::get_total_discount(false);
             $data['order_tax'] = jigoshop_cart::get_taxes_as_string();
             $data['order_tax_no_shipping_tax'] = jigoshop_cart::get_total_cart_tax_without_shipping_tax();
             $data['order_tax_divisor'] = jigoshop_cart::get_tax_divisor();
             $data['order_shipping_tax'] = jigoshop_cart::get_shipping_tax();
             $data['order_total'] = jigoshop_cart::get_total(false);
             $data['order_total_prices_per_tax_class_ex_tax'] = jigoshop_cart::get_price_per_tax_class_ex_tax();
             if ($this->valid_euvatno) {
                 $data['order_tax'] = '';
                 $temp = jigoshop_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 (jigoshop_cart::get_cart() as $values) {
                 /** @var jigoshop_product $product */
                 $product = $values['data'];
                 // Check stock levels
                 if (!$product->has_enough_stock($values['quantity'])) {
                     jigoshop::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.', 'jigoshop'), $product->get_title()));
                     if (self::get_options()->get('jigoshop_show_stock') == 'yes') {
                         jigoshop::add_error(sprintf(__('We have only %d available at this time.', 'jigoshop'), $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) jigoshop_session::instance()->customized_products;
                 $custom = isset($custom_products[$product_id]) ? $custom_products[$product_id] : '';
                 if (!empty($custom)) {
                     unset($custom_products[$product_id]);
                     jigoshop_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 (jigoshop::has_errors()) {
                 return false;
             }
             // Insert or update the post data
             $create_new_order = true;
             $order_data = array('post_type' => 'shop_order', 'post_title' => 'Order – ' . date('F j, Y @ h:i A'), 'post_status' => 'publish', 'post_excerpt' => $this->posted['order_comments'], 'post_author' => 1);
             $order_id = 0;
             if (isset(jigoshop_session::instance()->order_awaiting_payment) && jigoshop_session::instance()->order_awaiting_payment > 0) {
                 $order_id = absint(jigoshop_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) {
                 jigoshop::add_error(__('Error: Unable to create order. Please try again.', 'jigoshop'));
                 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 jigoshop_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('jigoshop_new_order', $order_id);
             } else {
                 do_action('jigoshop_resume_order', $order_id);
             }
             do_action('jigoshop_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
                 jigoshop_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
                 jigoshop_cart::empty_cart();
                 // Redirect to success/confirmation/payment page
                 $checkout_redirect = apply_filters('jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks'));
                 return array('result' => 'redirect', 'redirect' => $checkout_redirect);
             }
         }
     }
     return true;
 }
示例#5
0
function jigoshop_ajax_update_order_review()
{
    check_ajax_referer('update-order-review', 'security');
    if (!defined('JIGOSHOP_CHECKOUT')) {
        define('JIGOSHOP_CHECKOUT', true);
    }
    jigoshop_cart::get_cart();
    if (sizeof(jigoshop_cart::$cart_contents) == 0) {
        echo '<p class="error">' . __('Sorry, your session has expired.', 'jigoshop') . ' <a href="' . home_url() . '">' . __('Return to homepage &rarr;', 'jigoshop') . '</a></p>';
        exit;
    }
    do_action('jigoshop_checkout_update_order_review', $_POST['post_data']);
    if (isset($_POST['shipping_method'])) {
        $shipping_method = explode(":", $_POST['shipping_method']);
        jigoshop_session::instance()->chosen_shipping_method_id = $shipping_method[0];
        if (is_numeric($shipping_method[2])) {
            jigoshop_session::instance()->selected_rate_id = $shipping_method[2];
        }
    }
    if (!empty($_POST['coupon_code'])) {
        jigoshop_cart::add_discount(sanitize_title($_POST['coupon_code']));
        jigoshop::show_messages();
    }
    if (isset($_POST['country'])) {
        jigoshop_customer::set_country($_POST['country']);
    }
    if (isset($_POST['state'])) {
        jigoshop_customer::set_state($_POST['state']);
    }
    if (isset($_POST['postcode'])) {
        jigoshop_customer::set_postcode($_POST['postcode']);
    }
    if (isset($_POST['s_country'])) {
        jigoshop_customer::set_shipping_country($_POST['s_country']);
    }
    if (isset($_POST['s_state'])) {
        jigoshop_customer::set_shipping_state($_POST['s_state']);
    }
    if (isset($_POST['s_postcode'])) {
        jigoshop_customer::set_shipping_postcode($_POST['s_postcode']);
    }
    jigoshop_cart::calculate_totals();
    do_action('jigoshop_checkout_order_review');
    die;
}
<?php

get_header();
?>

<div class="main-wrapper-item"> 
    <div class="container post-wrap">
        <div class="row-fluid">   
            <div id="content" class="span12">
                
                <?php 
$cart = jigoshop_cart::get_cart();
$nocarterrors = true;
foreach ($cart as $cart_item_key => $values) {
    if ($values['product_id'] == esc_attr(get_theme_mod('_home_adquira_btn_link', '183')) && $values['quantity'] > 1) {
        $jigoerror = 'Só é permitida a aquisição de um ';
        $jigoerror .= get_bloginfo('name');
        $jigoerror .= ' por vez.  Por favor, reduza a quantidade para 1 e tente novamente.';
        jigoshop::add_error($jigoerror);
        $nocarterrors = false;
    }
    if ($values['product_id'] == esc_attr(get_theme_mod('_home_adquira_abrangencia_btn_link', '188')) && $values['quantity'] > 1) {
        jigoshop::add_error('A abrangência familiar vale para toda a família.  Não é necessário adquirir mais de uma abrangência familiar por plano.  Por favor, reduza a quantidade para 1 e tente novamente.');
        $nocarterrors = false;
    }
}
jigoshop::show_messages();
?>
                
                <div class="whiterogue-jigoshop-title">
                    início da contratação