public function __construct() { parent::__construct(); $options = Jigoshop_Base::get_options(); $this->id = 'free_shipping'; $this->enabled = $options->get('jigoshop_free_shipping_enabled'); $this->title = $options->get('jigoshop_free_shipping_title'); $this->min_amount = $options->get('jigoshop_free_shipping_minimum_amount'); $this->availability = $options->get('jigoshop_free_shipping_availability'); $this->countries = $options->get('jigoshop_free_shipping_countries'); $session = jigoshop_session::instance(); if (isset($session->chosen_shipping_method_id) && $session->chosen_shipping_method_id == $this->id) { $this->chosen = true; } add_action('jigoshop_settings_scripts', array($this, 'admin_scripts')); }
public function __construct() { parent::__construct(); $options = Jigoshop_Base::get_options(); $this->id = 'local_pickup'; $this->enabled = $options->get('jigoshop_local_pickup_enabled'); $this->title = $options->get('jigoshop_local_pickup_title'); $this->fee = $options->get('jigoshop_local_pickup_handling_fee'); $this->availability = $options->get('jigoshop_local_pickup_availability'); $this->countries = $options->get('jigoshop_local_pickup_countries'); $session = jigoshop_session::instance(); if (isset($session->chosen_shipping_method_id) && $session->chosen_shipping_method_id == $this->id) { $this->chosen = true; } add_action('jigoshop_settings_scripts', array($this, 'admin_scripts')); }
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())); }
/** * @param $tax_class string Tax class to get tax for. * @return float Tax value for current shipping and selected tax class. */ public function get_shipping_tax($tax_class) { if (isset($this->tax_amounts[$tax_class]) && isset($this->tax_amounts[$tax_class][jigoshop_session::instance()->chosen_shipping_method_id . jigoshop_session::instance()->selected_rate_id])) { return $this->tax_amounts[$tax_class][jigoshop_session::instance()->chosen_shipping_method_id . jigoshop_session::instance()->selected_rate_id] / 100; } return 0.0; }
/** * 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) { jigoshop_session::instance()->selected_rate_id = $i; break; } } } }
</strong></td> <td><strong><?php echo jigoshop_cart::get_total(); ?> </strong></td> </tr> </tfoot> <tbody> <?php foreach (jigoshop_cart::$cart_contents as $item_id => $values) { /** @var jigoshop_product $product */ $product = $values['data']; if ($product->exists() && $values['quantity'] > 0) { $variation = jigoshop_cart::get_item_data($values); $customization = ''; $custom_products = (array) jigoshop_session::instance()->customized_products; $product_id = !empty($values['variation_id']) ? $values['variation_id'] : $values['product_id']; $custom = isset($custom_products[$product_id]) ? $custom_products[$product_id] : ''; ?> <tr> <td class="product-name"> <?php echo $product->get_title() . $variation; if (!empty($custom)) { $label = apply_filters('jigoshop_customized_product_label', __(' Personal: ', 'jigoshop')); ?> <dl class="customization"> <dt class="customized_product_label"> <?php echo $label; ?>
function jigoshop_frontend_scripts() { $options = Jigoshop_Base::get_options(); $frontend_css = JIGOSHOP_URL . '/assets/css/frontend.css'; $theme_css = file_exists(get_stylesheet_directory() . '/jigoshop/style.css') ? get_stylesheet_directory_uri() . '/jigoshop/style.css' : $frontend_css; if ($options->get('jigoshop_disable_css') == 'no') { if ($options->get('jigoshop_frontend_with_theme_css') == 'yes' && $frontend_css != $theme_css) { jrto_enqueue_style('frontend', 'jigoshop_theme_styles', $frontend_css); } jrto_enqueue_style('frontend', 'jigoshop_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', 'jigoshop_global', JIGOSHOP_URL . '/assets/js/global.js', array('jquery'), array('in_footer' => true)); if ($options->get('jigoshop_disable_fancybox') == 'no') { jrto_enqueue_script('frontend', 'prettyPhoto', JIGOSHOP_URL . '/assets/js/jquery.prettyPhoto.js', array('jquery'), array('in_footer' => true)); jrto_enqueue_style('frontend', 'prettyPhoto', JIGOSHOP_URL . '/assets/css/prettyPhoto.css'); } jrto_enqueue_script('frontend', 'jigoshop-cart', JIGOSHOP_URL . '/assets/js/cart.js', array('jquery'), array('in_footer' => true, 'page' => JIGOSHOP_CART)); jrto_enqueue_script('frontend', 'jigoshop-checkout', JIGOSHOP_URL . '/assets/js/checkout.js', array('jquery', 'jquery-blockui'), array('in_footer' => true, 'page' => array(JIGOSHOP_CHECKOUT, JIGOSHOP_PAY))); jrto_enqueue_script('frontend', 'jigoshop-validation', JIGOSHOP_URL . '/assets/js/validation.js', array(), array('in_footer' => true, 'page' => JIGOSHOP_CHECKOUT)); jrto_enqueue_script('frontend', 'jigoshop-payment', JIGOSHOP_URL . '/assets/js/pay.js', array('jquery'), array('page' => JIGOSHOP_PAY)); jrto_enqueue_script('frontend', 'jigoshop-single-product', JIGOSHOP_URL . '/assets/js/single-product.js', array('jquery'), array('in_footer' => true, 'page' => JIGOSHOP_PRODUCT)); jrto_enqueue_script('frontend', 'jigoshop-countries', JIGOSHOP_URL . '/assets/js/countries.js', array(), array('in_footer' => true, 'page' => array(JIGOSHOP_CHECKOUT, JIGOSHOP_CART, JIGOSHOP_EDIT_ADDRESS))); /* Script.js variables */ // TODO: clean this up, a lot aren't even used anymore, do away with it $jigoshop_params = array('ajax_url' => admin_url('admin-ajax.php', 'jigoshop'), 'assets_url' => JIGOSHOP_URL, 'validate_postcode' => $options->get('jigoshop_enable_postcode_validating', 'no'), 'checkout_url' => admin_url('admin-ajax.php?action=jigoshop-checkout', 'jigoshop'), 'currency_symbol' => get_jigoshop_currency_symbol(), 'get_variation_nonce' => wp_create_nonce("get-variation"), 'load_fancybox' => $options->get('jigoshop_disable_fancybox') == 'no', 'option_guest_checkout' => $options->get('jigoshop_enable_guest_checkout'), 'select_state_text' => __('Select a state…', 'jigoshop'), 'state_text' => __('state', 'jigoshop'), 'ratings_message' => __('Please select a star to rate your review.', 'jigoshop'), 'update_order_review_nonce' => wp_create_nonce("update-order-review"), 'billing_state' => jigoshop_customer::get_state(), 'shipping_state' => jigoshop_customer::get_shipping_state(), 'is_checkout' => is_page(jigoshop_get_page_id('checkout')) || is_page(jigoshop_get_page_id('pay')), 'error_hide_time' => Jigoshop_Base::get_options()->get('jigoshop_error_disappear_time', 8000), 'message_hide_time' => Jigoshop_Base::get_options()->get('jigoshop_message_disappear_time', 4000)); if (isset(jigoshop_session::instance()->min_price)) { $jigoshop_params['min_price'] = $_GET['min_price']; } if (isset(jigoshop_session::instance()->max_price)) { $jigoshop_params['max_price'] = $_GET['max_price']; } $jigoshop_params = apply_filters('jigoshop_params', $jigoshop_params); jrto_localize_script('jigoshop_global', 'jigoshop_params', $jigoshop_params); }
function jigoshop_clear_cart_after_payment($url = false) { if (isset(jigoshop_session::instance()->order_awaiting_payment) && jigoshop_session::instance()->order_awaiting_payment > 0) { $order = new jigoshop_order(jigoshop_session::instance()->order_awaiting_payment); if ($order->id > 0 && ($order->status == 'completed' || $order->status == 'processing')) { jigoshop_cart::empty_cart(); unset(jigoshop_session::instance()->order_awaiting_payment); } } }
public static function remove_coupon($code) { if (!is_array(jigoshop_session::instance()->coupons)) { return false; } /* Loop to find the key of this coupon */ foreach (jigoshop_session::instance()->coupons as $key => $coupon) { if ($code == $coupon) { unset(jigoshop_cart::$applied_coupons[$key]); $data = (array) jigoshop_session::instance()->coupons; unset($data[$key]); jigoshop_session::instance()->coupons = $data; return true; } } }
/** * 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; }
/** * 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']) { jigoshop::add_error(__("There is already an 'individual use' coupon on the Cart. No other coupons can be added until it is removed.", 'jigoshop')); 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)) { jigoshop::add_error(__("This is an 'individual use' coupon. All other discount coupons have been removed.", 'jigoshop')); 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; } // select free shipping method if ($coupon['free_shipping']) { if (Jigoshop_Base::get_options()->get('jigoshop_select_free_shipping_method') == 'yes') { jigoshop_session::instance()->chosen_shipping_method_id = 'free_shipping'; } } jigoshop_session::instance()->coupons = self::$applied_coupons; jigoshop::add_message(__('Discount coupon applied successfully.', 'jigoshop')); return true; }
/** * prints locator column in body of table of product lists on order page * * @package Jigoshop * @subpackage Jigoshop Order Locator * @since 0.1 * **/ function jigoshop_locator_order_item_values($_product, $item = false) { global $post; if (!isset($post)) { $post = jigoshop_session::instance()->current_admin_order; } // dirty trick $row = jigoshop_session::instance()->current_admin_order_item_count += 1; echo '<td>' . PHP_EOL; if ($item && !empty($item)) { for ($n = 1; $n < $item['qty'] + 1; $n++) { $locator = jigoshop_generate_locator($post->ID, $item['id'], $row, $n); if (!empty($locator)) { echo "<code style=\"font-size: 13px; line-height:2em\">{$locator}</code><br>"; } } } else { $locator = jigoshop_generate_locator($post->ID, $_product->ID, $row); if (!empty($locator)) { echo "<code style=\"font-size: 13px; line-height:2em\">{$locator}</code><br>"; } } echo '</td>' . PHP_EOL; }
/** * Redirection hook which stores messages into session data * * @param $location * @param $status * @return string Location */ public static function redirect($location, $status = null) { jigoshop_session::instance()->errors = self::$errors; jigoshop_session::instance()->messages = self::$messages; return apply_filters('jigoshop_session_location_filter', $location); }
public function jigoshop_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, 'jigoshop_price_filter', true) && !is_admin()) { wp_enqueue_script('jquery-ui-slider'); } unset(jigoshop_session::instance()->min_price); unset(jigoshop_session::instance()->max_price); if (isset($_GET['min_price'])) { jigoshop_session::instance()->min_price = $_GET['min_price']; } if (isset($_GET['max_price'])) { jigoshop_session::instance()->max_price = $_GET['max_price']; } }
/** * 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(jigoshop_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('jigoshop_payment_complete', $this->id); }
/** * Calculate the shipping price * * @param $tax jigoshop_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(jigoshop_session::instance()->chosen_shipping_method_id)) { $chosen_method = jigoshop_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(jigoshop_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 jigoshop 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(jigoshop_session::instance()->selected_rate_id); self::$shipping_tax = $_available_methods[$chosen_method]->get_selected_tax(jigoshop_session::instance()->selected_rate_id); self::$shipping_label = $_available_methods[$chosen_method]->get_selected_service(jigoshop_session::instance()->selected_rate_id); } } //sizeof available methods } //self enabled == 'yes' }
/** * Logs viewed products into the session * * @var $post WP_Post * @var $_product jigoshop_product * @return void **/ public function jigoshop_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(jigoshop_session::instance()->recently_viewed_products)) { $viewed = array(); jigoshop_session::instance()->recently_viewed_products = $viewed; } // If the product isn't in the list, add it if (!in_array($post->ID, jigoshop_session::instance()->recently_viewed_products)) { $viewed = jigoshop_session::instance()->recently_viewed_products; $viewed[] = $post->ID; jigoshop_session::instance()->recently_viewed_products = $viewed; } if (sizeof(jigoshop_session::instance()->recently_viewed_products) > $number) { $viewed = jigoshop_session::instance()->recently_viewed_products; array_shift($viewed); jigoshop_session::instance()->recently_viewed_products = $viewed; } }
function jigoshop_product_customize_panel() { global $_product; if (isset($_POST['Submit']) && $_POST['Submit'] == __('Save Personalization', 'jigoshop')) { $custom_products = (array) jigoshop_session::instance()->customized_products; $custom_products[$_POST['customized_id']] = sanitize_text_field(stripslashes($_POST['jigoshop_customized_product'])); jigoshop_session::instance()->customized_products = $custom_products; } if (get_post_meta($_product->ID, 'customizable', true) == 'yes') { $custom_products = (array) jigoshop_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.', 'jigoshop'), $custom_length); echo '<div class="panel" id="tab-customize">'; echo '<p>' . apply_filters('jigoshop_product_customize_heading', __('Enter your personal information as you want it to appear on the product.<br />', 'jigoshop') . $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="jigoshop_customized_product" name="jigoshop_customized_product" cols="60" rows="4"><?php echo esc_textarea($custom); ?> </textarea> <?php } else { ?> <input type="text" id="jigoshop_customized_product" name="jigoshop_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", 'jigoshop'); ?> " /></p> </form> <?php echo '</div>'; } }
/** * 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(jigoshop_session::instance()->customer); $this->set_default_customer(); }
function my_cart($atts) { $errors = array(); unset(jigoshop_session::instance()->selected_rate_id); // Process Discount Codes if (isset($_POST['apply_coupon']) && $_POST['apply_coupon'] && jigoshop::verify_nonce('cart')) { $coupon_code = stripslashes(trim($_POST['coupon_code'])); jigoshop_cart::add_discount($coupon_code); // Update Shipping } elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && jigoshop::verify_nonce('cart')) { 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(); // choses the method selected by user. } // Re-Calc prices. This needs to happen every time the cart page is loaded and after checking post results. It will happen twice for coupon. jigoshop_cart::calculate_totals(); $result = jigoshop_cart::check_cart_item_stock(); if (is_wp_error($result)) { jigoshop::add_error($result->get_error_message()); } jigoshop::show_messages(); if (sizeof(jigoshop_cart::$cart_contents) == 0) { echo '<p>' . __('Your cart is empty.', 'jigoshop') . '</p>'; ?> <p><a href="<?php echo esc_url(jigoshop_cart::get_shop_url()); ?> " class="button"><?php _e('← Return to Shop', 'jigoshop'); ?> </a></p><?php return; } ?> <form action="<?php echo esc_url(jigoshop_cart::get_cart_url()); ?> " method="post"> <table class="shop_table cart" cellspacing="0" id="shop-cart"> <thead> <tr> <th class="product-remove">Remove</th> <th class="product-thumbnail"></th> <th class="product-name"><span class="nobr"><?php _e('Product Name', 'jigoshop'); ?> </span></th> <th class="product-price"><span class="nobr"><?php _e('Unit Price', 'jigoshop'); ?> </span></th> <th class="product-quantity"><?php _e('Quantity', 'jigoshop'); ?> </th> <th class="product-subtotal"><?php _e('Price', 'jigoshop'); ?> </th> </tr> <?php do_action('jigoshop_shop_table_cart_head'); ?> </thead> <tbody> <?php if (sizeof(jigoshop_cart::$cart_contents) > 0) { foreach (jigoshop_cart::$cart_contents as $cart_item_key => $values) { $_product = $values['data']; if ($_product->exists() && $values['quantity'] > 0) { $additional_description = jigoshop_cart::get_item_data($values); ?> <tr> <td class="product-remove"><a href="<?php echo esc_url(jigoshop_cart::get_remove_url($cart_item_key)); ?> " class="remove" title="<?php echo esc_attr(__('Remove this item.', 'jigoshop')); ?> ">×</a></td> <td class="product-thumbnail"><a href="<?php echo esc_url(apply_filters('jigoshop_product_url_display_in_cart', get_permalink($values['product_id']), $cart_item_key)); ?> "> <?php if ($values['variation_id'] && has_post_thumbnail($values['variation_id'])) { echo get_the_post_thumbnail($values['variation_id'], 'shop_tiny'); } else { if (has_post_thumbnail($values['product_id'])) { echo get_the_post_thumbnail($values['product_id'], 'shop_tiny'); } else { echo '<img src="' . jigoshop::assets_url() . '/assets/images/placeholder.png" alt="Placeholder" width="' . jigoshop::get_var('shop_tiny_w') . '" height="' . jigoshop::get_var('shop_tiny_h') . '" />'; } } ?> </a> </td> <td class="product-name"> <a href="<?php echo esc_url(apply_filters('jigoshop_product_url_display_in_cart', get_permalink($values['product_id']), $cart_item_key)); ?> "><?php echo apply_filters('jigoshop_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) jigoshop_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('jigoshop_customized_product_label', __('Personal: ', 'jigoshop')); ?> </dt> <dd class="customized_product"><?php echo esc_textarea($custom); ?> </dd> </dl> <?php } ?> </td> <td class="product-price"><span class="m-label">Unit price:</span><?php echo jigoshop_price($_product->get_price()); ?> </td> <td class="product-quantity"> <span class="m-label">Quantity:</span> <div class="quantity"><input name="cart[<?php echo $cart_item_key; ?> ][qty]" value="<?php echo esc_attr($values['quantity']); ?> " size="4" title="Qty" class="input-text qty text" maxlength="12" /></div> </td> <td class="product-subtotal"><span class="m-label">Price:</span><?php echo jigoshop_price($_product->get_price() * $values['quantity']); ?> </td> </tr> <?php } } } do_action('jigoshop_shop_table_cart_body'); ?> </tbody> <tfoot> <tr> <td colspan="6" class="actions"> <?php $coupons = JS_Coupons::get_coupons(); if (!empty($coupons)) { ?> <div class="coupon"> <label for="coupon_code"><?php _e('Coupon', 'jigoshop'); ?> :</label> <input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" /> <input type="submit" class="button" name="apply_coupon" value="<?php _e('Apply Coupon', 'jigoshop'); ?> " /> </div> <?php } ?> <?php jigoshop::nonce_field('cart'); ?> <input type="submit" class="button" name="update_cart" value="<?php _e('Update Shopping Cart', 'jigoshop'); ?> " /> <a href="<?php echo esc_url(jigoshop_cart::get_checkout_url()); ?> " class="checkout-button button-alt"><?php _e('Proceed to Checkout →', 'jigoshop'); ?> </a> </td> </tr> <?php if (count(jigoshop_cart::$applied_coupons)) { ?> <tr> <td colspan="6" class="applied-coupons"> <div> <span class="applied-coupons-label"><?php _e('Applied Coupons: ', 'jigoshop'); ?> </span> <?php foreach (jigoshop_cart::$applied_coupons as $code) { ?> <a href="?unset_coupon=<?php echo $code; ?> " id="<?php echo $code; ?> " class="applied-coupons-values"><?php echo $code; ?> <span class="close">×</span> </a> <?php } ?> </div> </td> </tr> <?php } do_action('jigoshop_shop_table_cart_foot'); ?> </tfoot> <?php do_action('jigoshop_shop_table_cart'); ?> </table> </form> <div class="cart-collaterals"> <?php do_action('cart-collaterals'); ?> <div class="cart_totals"> <?php // Hide totals if customer has set location and there are no methods going there $available_methods = jigoshop_shipping::get_available_shipping_methods(); $jigoshop_options = Jigoshop_Base::get_options(); if ($available_methods || !jigoshop_customer::get_shipping_country() || !jigoshop_shipping::is_enabled()) { ?> <h2><?php _e('Cart Totals', 'jigoshop'); ?> </h2> <div class="cart_totals_table"> <table cellspacing="0" cellpadding="0"> <tbody> <tr> <?php $price_label = jigoshop_cart::show_retail_price() ? __('Retail Price', 'jigoshop') : __('Subtotal', 'jigoshop'); ?> <th class="cart-row-subtotal-title"><?php echo $price_label; ?> </th> <td class="cart-row-subtotal"><?php echo jigoshop_cart::get_cart_subtotal(); ?> </td> </tr> <?php if (jigoshop_cart::get_cart_shipping_total()) { ?> <tr> <th class="cart-row-shipping-title"><?php _e('Shipping', 'jigoshop'); ?> <small><?php echo jigoshop_countries::shipping_to_prefix() . ' ' . __(jigoshop_countries::$countries[jigoshop_customer::get_shipping_country()], 'jigoshop'); ?> </small></th> <td class="cart-row-shipping"><?php echo jigoshop_cart::get_cart_shipping_total(); ?> <small><?php echo jigoshop_cart::get_cart_shipping_title(); ?> </small></td> </tr> <?php } ?> <?php if (jigoshop_cart::show_retail_price()) { ?> <tr> <th class="cart-row-subtotal-title"><?php _e('Subtotal', 'jigoshop'); ?> </th> <td class="cart-row-subtotal"><?php echo jigoshop_cart::get_cart_subtotal(true, true); ?> </td> </tr> <?php } ?> <?php if (jigoshop_cart::tax_after_coupon()) { ?> <tr class="discount"> <th class="cart-row-discount-title"><?php _e('Discount', 'jigoshop'); ?> </th> <td class="cart-row-discount">-<?php echo jigoshop_cart::get_total_discount(); ?> </td> </tr> <?php } ?> <?php if (Jigoshop_Base::get_options()->get_option('jigoshop_calc_taxes') == 'yes') { foreach (jigoshop_cart::get_applied_tax_classes() as $tax_class) { if (jigoshop_cart::get_tax_for_display($tax_class)) { ?> <tr> <th class="cart-row-tax-title"><?php echo jigoshop_cart::get_tax_for_display($tax_class); ?> </th> <td class="cart-row-tax"><?php echo jigoshop_cart::get_tax_amount($tax_class); ?> </td> </tr> <?php } } } ?> <?php if (!jigoshop_cart::tax_after_coupon() && jigoshop_cart::get_total_discount()) { ?> <tr class="discount"> <th class="cart-row-discount-title"><?php _e('Discount', 'jigoshop'); ?> </th> <td class="cart-row-discount">-<?php echo jigoshop_cart::get_total_discount(); ?> </td> </tr> <?php } ?> <tr> <th class="cart-row-total-title"><strong><?php _e('Total', 'jigoshop'); ?> </strong></th> <td class="cart-row-total"><strong><?php echo jigoshop_cart::get_total(); ?> </strong></td> </tr> </tbody> </table> </div> <?php } else { echo '<p>' . __(jigoshop_shipping::get_shipping_error_message(), 'jigoshop') . '</p>'; } ?> </div> <?php jigoshop_shipping_calculator(); ?> </div> <?php }