public function is_available() { if ($this->get_enabled() == "no") { return false; } if (isset(jigoshop_cart::$cart_contents_total_ex_dl) && isset($this->min_amount) && $this->min_amount && apply_filters('jigoshop_shipping_min_amount', $this->min_amount, $this) > jigoshop_cart::$cart_contents_total_ex_dl - jigoshop_cart::$discount_total) { return false; } if (is_array($this->get_ship_to_countries()) && !in_array(jigoshop_customer::get_shipping_country(), $this->get_ship_to_countries())) { $this->set_error_message('Sorry, it seems that there are no available shipping methods to your location. Please contact us if you require assistance or wish to make alternate arrangements.'); return false; } return !$this->has_error; }
public function is_available() { if ($this->enabled=="no") return false; if (isset(jigoshop_cart::$cart_contents_total) && isset($this->min_amount) && $this->min_amount && $this->min_amount > jigoshop_cart::$cart_contents_total) return false; $ship_to_countries = ''; if ($this->availability == 'specific') : $ship_to_countries = $this->countries; else : if (get_option('jigoshop_allowed_countries')=='specific') : $ship_to_countries = get_option('jigoshop_specific_allowed_countries'); endif; endif; if (is_array($ship_to_countries)) : if (!in_array(jigoshop_customer::get_shipping_country(), $ship_to_countries)) return false; endif; return true; }
function jigoshop_shipping_calculator() { if (jigoshop_cart::needs_shipping()) { ?> <form class="shipping_calculator" action="<?php echo jigoshop_cart::get_cart_url(); ?> " method="post"> <h4><a href="#" class="shipping-calculator-button"><?php _e('Calculate Shipping', 'jigoshop'); ?> <span>↓</span></a></h4> <section class="shipping-calculator-form"> <p class="form-row"> <select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state" rel="calc_shipping_state"> <option value=""><?php _e('Select a country…', 'jigoshop'); ?> </option> <?php foreach (jigoshop_countries::get_allowed_countries() as $key => $value) { echo '<option value="' . $key . '"'; if (jigoshop_customer::get_shipping_country() == $key) { echo 'selected="selected"'; } echo '>' . $value . '</option>'; } ?> </select> </p> <div class="col2-set"> <p class="form-row col-1"> <?php $current_cc = jigoshop_customer::get_shipping_country(); $current_r = jigoshop_customer::get_shipping_state(); $states = jigoshop_countries::$states; if (isset($states[$current_cc][$current_r])) { // Dropdown ?> <span> <select name="calc_shipping_state" id="calc_shipping_state"><option value=""><?php _e('Select a state…', 'jigoshop'); ?> </option><?php foreach ($states[$current_cc] as $key => $value) { echo '<option value="' . $key . '"'; if ($current_r == $key) { echo 'selected="selected"'; } echo '>' . $value . '</option>'; } ?> </select> </span> <?php } else { // Input ?> <input type="text" class="input-text" value="<?php echo $current_r; ?> " placeholder="<?php _e('state', 'jigoshop'); ?> " name="calc_shipping_state" id="calc_shipping_state" /> <?php } ?> </p> <p class="form-row col-2"> <input type="text" class="input-text" value="<?php echo jigoshop_customer::get_shipping_postcode(); ?> " placeholder="<?php _e('Postcode/Zip', 'jigoshop'); ?> " title="<?php _e('Postcode', 'jigoshop'); ?> " name="calc_shipping_postcode" id="calc_shipping_postcode" /> </p> </div> <p><button type="submit" name="calc_shipping" value="1" class="button"><?php _e('Update Totals', 'jigoshop'); ?> </button></p> <?php jigoshop::nonce_field('cart'); ?> </section> </form> <?php } }
/** * Outputs a form field * * @param array $args contains a list of args for showing the field, merged with defaults (below) * @return string */ public static function address_form_field($args) { $defaults = array('type' => 'text', 'name' => '', 'label' => '', 'placeholder' => '', 'required' => false, 'class' => array(), 'label_class' => array(), 'rel' => '', 'return' => false, 'options' => array(), 'value' => ''); $args = wp_parse_args($args, $defaults); if ($args['required']) { $required = ' <span class="required">*</span>'; $input_required = ' input-required'; } else { $required = ''; $input_required = ''; } if (in_array('form-row-last', $args['class'])) { $after = '<div class="clear"></div>'; } else { $after = ''; } switch ($args['type']) { case "country": $current_c = self::get_value($args['name']); $is_shipping_c = strpos($args['name'], 'shipping'); if (!$current_c) { if ($is_shipping_c === false) { $current_c = jigoshop_customer::get_country(); } else { $current_c = jigoshop_customer::get_shipping_country(); } } // Remove 'Select a Country' option from drop-down menu for countries. // There is no need to have it, because was assume when user hasn't selected // a country that they are from the shop base country. $field = '<p class="form-row ' . implode(' ', $args['class']) . '"> <label for="' . esc_attr($args['name']) . '" class="' . esc_attr(implode(' ', $args['label_class'])) . '">' . $args['label'] . $required . '</label> <select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="country_to_state" rel="' . esc_attr($args['rel']) . '">'; foreach (jigoshop_countries::get_allowed_countries() as $key => $value) { $field .= '<option value="' . esc_attr($key) . '"'; if (self::get_value($args['name']) == $key) { $field .= ' selected="selected"'; } elseif (self::get_value($args['name']) && $current_c == $key) { $field .= ' selected="selected"'; } $field .= '>' . __($value, 'jigoshop') . '</option>'; } $field .= '</select></p>' . $after; break; case "state": $field = '<p class="form-row ' . implode(' ', $args['class']) . '"> <label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>'; $is_shipping_s = strpos($args['name'], 'shipping'); $current_cc = self::get_value($args['rel']); if (!$current_cc) { if ($is_shipping_s === false) { $current_cc = jigoshop_customer::get_country(); } else { $current_cc = jigoshop_customer::get_shipping_country(); } } $current_r = self::get_value($args['name']); if (!$current_r) { if ($is_shipping_s === false) { $current_r = jigoshop_customer::get_state(); } else { $current_r = jigoshop_customer::get_shipping_state(); } } $states = jigoshop_countries::get_states($current_cc); if (!empty($states)) { // Dropdown $field .= '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($input_required) . '"><option value="">' . __('Select a state…', 'jigoshop') . '</option>'; foreach ($states as $key => $value) { $field .= '<option value="' . esc_attr($key) . '"'; if ($current_r == $key) { $field .= ' selected="selected"'; } $field .= '>' . __($value, 'jigoshop') . '</option>'; } $field .= '</select>'; } else { // Input $field .= '<input type="text" class="input-text" value="' . esc_attr($current_r) . '" placeholder="' . __('State/Province', 'jigoshop') . '" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" />'; } $field .= '</p>' . $after; break; case "postcode": $current_pc = self::get_value($args['name']); $is_shipping_pc = strpos($args['name'], 'shipping'); if (!$current_pc) { if ($is_shipping_pc === false) { $current_pc = jigoshop_customer::get_postcode(); } else { $current_pc = jigoshop_customer::get_shipping_postcode(); } } $field = '<p class="form-row ' . implode(' ', $args['class']) . '"> <label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label> <input type="text" class="input-text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" value="' . esc_attr($current_pc) . '" /> </p>' . $after; break; case "textarea": $field = '<p class="form-row ' . implode(' ', $args['class']) . '"> <label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label> <textarea name="' . esc_attr($args['name']) . '" class="input-text' . esc_attr($input_required) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" cols="5" rows="2">' . esc_textarea(self::get_value($args['name'])) . '</textarea> </p>' . $after; break; //Adds a drop down custom type //Adds a drop down custom type case "select": $field = '<p class="form-row ' . implode(' ', $args['class']) . '"> <label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>'; $field .= '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($input_required) . '">'; foreach ($args['options'] as $value => $label) { $field .= '<option value="' . esc_attr($value) . '"'; if (self::get_value($args['name']) == $value) { $field .= ' selected="selected"'; } $field .= '>' . __($label, 'jigoshop') . '</option>'; } $field .= '</select></p>' . $after; break; default: $field = '<p class="form-row ' . implode(' ', $args['class']) . '"> <label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label> <input type="' . $args['type'] . '" class="input-text' . esc_attr($input_required) . '" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" value="' . self::get_value($args['name']) . '" /> </p>' . $after; break; } $field = apply_filters('jigoshop_address_field_types', $field, $args); if ($args['return']) { return $field; } else { echo $field; return null; } }
/** * Get the tax rate based on the country and state. * * @param string $tax_class is the tax class that has shipping tax applied * @return mixed * @deprecated - use calculate_shipping_tax($price, $tax_classes) to calculate shipping taxes. No need to get the rates first */ function get_shipping_tax_rate($tax_class = '') { $this->shipping_tax_class = ''; $country = jigoshop_customer::get_shipping_country(); $state = jigoshop_customer::get_shipping_state(); // If we are here then shipping is taxable - work it out if ($tax_class) { // This will be per item shipping $rate = $this->find_rate($country, $state, $tax_class); if (isset($rate['shipping']) && $rate['shipping'] == 'yes') { $this->shipping_tax_class = $tax_class; return $rate['rate']; } else { // Get standard rate $rate = $this->find_rate($country, $state); if (isset($rate['shipping']) && $rate['shipping'] == 'yes') { $this->shipping_tax_class = '*'; //standard rate return $rate['rate']; } } } else { // This will be per order shipping - loop through the order and find the highest tax class rate $found_shipping_rates = array(); $customer_tax_classes = $this->get_tax_classes_for_customer(); foreach ($customer_tax_classes as $tax_class) { $found_rate = $this->find_rate($country, $state, $tax_class); if (isset($found_rate['shipping']) && $found_rate['shipping'] == 'yes') { $this->shipping_tax_class = $tax_class; $found_shipping_rates[] = $found_rate['rate']; } } if (sizeof($found_shipping_rates) > 0) { rsort($found_shipping_rates); return $found_shipping_rates[0]; } } return 0; // return false }
function jigoshop_shipping_calculator() { if (jigoshop_shipping::show_shipping_calculator()) { ?> <form class="shipping_calculator" action="<?php echo esc_url(jigoshop_cart::get_cart_url()); ?> " method="post"> <h2><a href="#" class="shipping-calculator-button"><?php _e('Calculate Shipping', 'jigoshop'); ?> <span>↓</span></a></h2> <section class="shipping-calculator-form"> <p class="form-row"> <select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state" rel="calc_shipping_state"> <?php foreach (jigoshop_countries::get_allowed_countries() as $key => $value) { ?> <option value="<?php echo esc_attr($key); ?> " <?php selected(jigoshop_customer::get_shipping_country(), $key); ?> ><?php echo $value; ?> </option> <?php } ?> </select> </p> <div class="col2-set"> <p class="form-row col-1"> <?php $current_cc = jigoshop_customer::get_shipping_country(); $current_r = jigoshop_customer::get_shipping_state(); $states = jigoshop_countries::$states; if (jigoshop_countries::country_has_states($current_cc)) { // Dropdown ?> <span> <select name="calc_shipping_state" id="calc_shipping_state"> <option value=""><?php _e('Select a state…', 'jigoshop'); ?> </option><?php foreach ($states[$current_cc] as $key => $value) { echo '<option value="' . esc_attr($key) . '"'; if ($current_r == $key) { echo 'selected="selected"'; } echo '>' . $value . '</option>'; } ?> </select> </span> <?php } else { // Input ?> <input type="text" class="input-text" value="<?php echo esc_attr($current_r); ?> " placeholder="<?php _e('state', 'jigoshop'); ?> " name="calc_shipping_state" id="calc_shipping_state" /> <?php } ?> </p> <p class="form-row col-2"> <input type="text" class="input-text" value="<?php echo esc_attr(jigoshop_customer::get_shipping_postcode()); ?> " placeholder="<?php _e('Postcode/Zip', 'jigoshop'); ?> " title="<?php _e('Postcode', 'jigoshop'); ?> " name="calc_shipping_postcode" id="calc_shipping_postcode" /> </p> <?php do_action('jigoshop_after_shipping_calculator_fields'); ?> </div> <p> <button type="submit" name="calc_shipping" value="1" class="button"><?php _e('Update Totals', 'jigoshop'); ?> </button> </p> <p> <?php $available_methods = jigoshop_shipping::get_available_shipping_methods(); foreach ($available_methods as $method) { for ($i = 0; $i < $method->get_rates_amount(); $i++) { ?> <div class="col2-set"> <p class="form-row col-1"> <?php echo '<input type="radio" name="shipping_rates" value="' . esc_attr($method->id . ':' . $i) . '"' . ' class="shipping_select"'; if ($method->get_cheapest_service() == $method->get_selected_service($i) && $method->is_chosen()) { echo ' checked>'; } else { echo '>'; } echo $method->get_selected_service($i); ?> <p class="form-row col-2"><?php if ($method->get_selected_price($i) > 0) { echo jigoshop_price($method->get_selected_price($i)); echo __(' (ex. tax)', 'jigoshop'); } else { echo __('Free', 'jigoshop'); } ?> </div> <?php } } ?> <input type="hidden" name="cart-url" value="<?php echo esc_attr(jigoshop_cart::get_cart_url()); ?> "> <?php jigoshop::nonce_field('cart'); ?> </section> </form> <?php } }
public static function get_cart_shipping_total($for_display = true, $order_exclude_tax = false) { /* Quit early if there is no shipping label. */ if (!jigoshop_shipping::get_label()) { return false; } // Do not display taxes if shipping country is not set if (jigoshop_customer::get_shipping_country() == '') { return false; } /* Shipping price is 0.00. */ if (jigoshop_shipping::get_total() <= 0) { return $for_display ? __('Free!', 'jigoshop') : 0; } /* Not calculating taxes. */ if (self::get_options()->get('jigoshop_calc_taxes') == 'no') { return $for_display ? jigoshop_price(self::$shipping_total) : number_format(self::$shipping_total, 2, '.', ''); } if (self::get_options()->get('jigoshop_prices_include_tax') == 'no' || $order_exclude_tax) { $return = $for_display ? jigoshop_price(self::$shipping_total) : number_format(self::$shipping_total, 2, '.', ''); if (self::$shipping_tax_total > 0 && $for_display) { $return .= ' <small>' . __('(ex. tax)', 'jigoshop') . '</small>'; } } else { $return = $for_display ? jigoshop_price(self::$shipping_total + self::$shipping_tax_total) : number_format(self::$shipping_total + self::$shipping_tax_total, 2, '.', ''); if (self::$shipping_tax_total > 0 && $for_display) { $return .= ' <small>' . __('(inc. tax)', 'jigoshop') . '</small>'; } } return $return; }
function estimated_for_prefix() { $return = ''; if (in_array(jigoshop_customer::get_country(), array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' ))) $return = __('the ', 'jigoshop'); $return = apply_filters('estimated_for_prefix', $return, jigoshop_customer::get_shipping_country()); return $return; }
function jigoshop_cart( $atts ) { $errors = array(); // 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); // Remove from cart elseif ( isset($_GET['remove_item']) && $_GET['remove_item'] > 0 && jigoshop::verify_nonce('cart', '_GET')) : jigoshop_cart::set_quantity( $_GET['remove_item'], 0 ); jigoshop::add_message( __('Cart updated.', 'jigoshop') ); // Update Cart elseif (isset($_POST['update_cart']) && $_POST['update_cart'] && jigoshop::verify_nonce('cart')) : $cart_totals = $_POST['cart']; if (sizeof(jigoshop_cart::$cart_contents)>0) : foreach (jigoshop_cart::$cart_contents as $item_id => $values) : if (isset($cart_totals[$item_id]['qty'])) jigoshop_cart::set_quantity( $item_id, $cart_totals[$item_id]['qty'] ); endforeach; endif; jigoshop::add_message( __('Cart updated.', 'jigoshop') ); // Update Shipping elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && jigoshop::verify_nonce('cart')) : unset($_SESSION['_chosen_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 ); endif; if ($country) : // Update customer location jigoshop_customer::set_location( $country, $state, $postcode ); jigoshop_customer::set_shipping_location( $country, $state, $postcode ); // Re-calc price jigoshop_cart::calculate_totals(); jigoshop::add_message( __('Shipping costs updated.', 'jigoshop') ); else : jigoshop_customer::set_shipping_location( '', '', '' ); jigoshop::add_message( __('Shipping costs updated.', 'jigoshop') ); endif; endif; $result = jigoshop_cart::check_cart_item_stock(); if (is_wp_error($result)) : jigoshop::add_error( $result->get_error_message() ); endif; jigoshop::show_messages(); if (sizeof(jigoshop_cart::$cart_contents)==0) : echo '<p>'.__('Your cart is empty.', 'jigoshop').'</p>'; return; endif; ?> <form action="<?php echo jigoshop_cart::get_cart_url(); ?>" method="post"> <table class="shop_table cart" cellspacing="0"> <thead> <tr> <th class="product-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> </thead> <tbody> <?php if (sizeof(jigoshop_cart::$cart_contents)>0) : foreach (jigoshop_cart::$cart_contents as $item_id => $values) : $_product = $values['data']; if ($_product->exists() && $values['quantity']>0) : echo ' <tr> <td class="product-remove"><a href="'.jigoshop_cart::get_remove_url($item_id).'" class="remove" title="Remove this item">×</a></td> <td class="product-thumbnail"><a href="'.get_permalink($item_id).'">'; if (has_post_thumbnail($item_id)) echo get_the_post_thumbnail($item_id, 'shop_tiny'); else echo '<img src="'.jigoshop::plugin_url(). '/assets/images/placeholder.png" alt="Placeholder" width="'.jigoshop::get_var('shop_tiny_w').'" height="'.jigoshop::get_var('shop_tiny_h').'" />'; echo ' </a></td> <td class="product-name"><a href="'.get_permalink($item_id).'">' . apply_filters('jigoshop_cart_product_title', $_product->get_title(), $_product) . '</a></td> <td class="product-price">'.jigoshop_price($_product->get_price()).'</td> <td class="product-quantity"><div class="quantity"><input name="cart['.$item_id.'][qty]" value="'.$values['quantity'].'" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div></td> <td class="product-subtotal">'.jigoshop_price($_product->get_price()*$values['quantity']).'</td> </tr>'; endif; endforeach; endif; do_action( 'jigoshop_shop_table_cart' ); ?> <tr> <td colspan="6" class="actions"> <div class="coupon"> <label for="coupon_code"><?php _e('Coupon', 'jigoshop'); ?>:</label> <input 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 jigoshop::nonce_field('cart') ?> <input type="submit" class="button" name="update_cart" value="<?php _e('Update Shopping Cart', 'jigoshop'); ?>" /> <a href="<?php echo jigoshop_cart::get_checkout_url(); ?>" class="checkout-button button-alt"><?php _e('Proceed to Checkout →', 'jigoshop'); ?></a> </td> </tr> </tbody> </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(); if ($available_methods || !jigoshop_customer::get_shipping_country() || !jigoshop_shipping::$enabled ) : ?> <h2><?php _e('Cart Totals', 'jigoshop'); ?></h2> <table cellspacing="0" cellpadding="0"> <tbody> <tr> <th><?php _e('Subtotal', 'jigoshop'); ?></th> <td><?php echo jigoshop_cart::get_cart_subtotal(); ?></td> </tr> <?php if (jigoshop_cart::get_cart_shipping_total()) : ?><tr> <th><?php _e('Shipping', 'jigoshop'); ?> <small><?php echo jigoshop_countries::shipping_to_prefix().' '.jigoshop_countries::$countries[ jigoshop_customer::get_shipping_country() ]; ?></small></th> <td><?php echo jigoshop_cart::get_cart_shipping_total(); ?> <small><?php echo jigoshop_cart::get_cart_shipping_title(); ?></small></td> </tr><?php endif; ?> <?php if (jigoshop_cart::get_cart_tax()) : ?><tr> <th><?php _e('Tax', 'jigoshop'); ?> <?php if (jigoshop_customer::is_customer_outside_base()) : ?><small><?php echo sprintf(__('estimated for %s', 'jigoshop'), jigoshop_countries::estimated_for_prefix() . jigoshop_countries::$countries[ jigoshop_countries::get_base_country() ] ); ?></small><?php endif; ?></th> <td><?php echo jigoshop_cart::get_cart_tax(); ?></td> </tr><?php endif; ?> <?php if (jigoshop_cart::get_total_discount()) : ?><tr class="discount"> <th><?php _e('Discount', 'jigoshop'); ?></th> <td>-<?php echo jigoshop_cart::get_total_discount(); ?></td> </tr><?php endif; ?> <tr> <th><strong><?php _e('Total', 'jigoshop'); ?></strong></th> <td><strong><?php echo jigoshop_cart::get_total(); ?></strong></td> </tr> </tbody> </table> <?php else : echo '<p>'.__('Sorry, it seems that there are no available shipping methods to your location. Please contact us if you require assistance or wish to make alternate arrangements.', 'jigoshop').'</p>'; endif; ?> </div> <?php jigoshop_shipping_calculator(); ?> </div> <?php }
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 }
?> </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(); if ($available_methods || !jigoshop_customer::get_shipping_country() || !jigoshop_shipping::is_enabled()) { do_action('jigoshop_before_cart_totals'); ?> <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;