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; } }
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); }
/** * 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 } }