/** * Find out if the customer should be taxed or not * * @param boolean $shippable tells if the cart has shippable items, and therefore we should use shipping country. Otherwise if not shippable items, we need to use the customer country. * @return boolean true if customer is taxable, false otherwise * @since 1.4 */ public static function is_taxable($shippable) { // if no taxes, than no one is taxable if (self::get_options()->get('jigoshop_calc_taxes') == 'no') { return false; } $shop_country = jigoshop_countries::get_base_country(); $my_country = jigoshop_tax::get_customer_country(); if (jigoshop_countries::is_eu_country($shop_country)) { return jigoshop_countries::is_eu_country($my_country); } return $shop_country == $my_country; }
function format_tax_rates_for_display($value) { $_tax = new jigoshop_tax(); $tax_classes = $_tax->get_tax_classes(); $tax_rates = Jigoshop_Base::get_options()->get('jigoshop_tax_rates'); if (empty($tax_rates)) { $tax_rates = array(); } $applied_all_states = array(); ob_start(); ?> <div id="jigoshop_tax_rates"> <table class="tax_rate_rules" cellspacing="0"> <thead> <tr> <th><?php _e('Remove', 'jigoshop'); ?> </th> <th><?php _e('Tax Classes', 'jigoshop'); ?> </th> <th><?php _e('Online Label', 'jigoshop'); ?> </th> <th><?php _e('Country/State', 'jigoshop'); ?> </th> <th><?php _e("Rate (%)", 'jigoshop'); ?> </th> <th><?php _e('Apply to shipping', 'jigoshop'); ?> </th> <th><?php _e('Compound', 'jigoshop'); ?> </th> </tr> </thead> <tfoot> <tr> <th><?php _e('Remove', 'jigoshop'); ?> </th> <th><?php _e('Tax Classes', 'jigoshop'); ?> </th> <th><?php _e('Online Label', 'jigoshop'); ?> </th> <th><?php _e('Country/State', 'jigoshop'); ?> </th> <th><?php _e("Rate (%)", 'jigoshop'); ?> </th> <th><?php _e('Apply to shipping', 'jigoshop'); ?> </th> <th><?php _e('Compound', 'jigoshop'); ?> </th> </tr> </tfoot> <tbody> <?php $i = -1; if ($tax_rates && is_array($tax_rates) && sizeof($tax_rates) > 0) { $tax_rates = $this->array_compare($tax_rates); foreach ($tax_rates as $rate) { if (isset($rate['is_all_states']) && in_array($rate['country'] . $rate['class'], $applied_all_states)) { continue; } $i++; // increment counter after check for all states having been applied echo '<tr class="tax_rate"><td><a href="#" class="remove button">×</a></td>'; echo '<td><select id="tax_classes[' . esc_attr($i) . ']" name="tax_classes[' . esc_attr($i) . ']"><option value="*">' . __('Standard Rate', 'jigoshop') . '</option>'; if ($tax_classes) { foreach ($tax_classes as $class) { echo '<option value="' . sanitize_title($class) . '"'; if (isset($rate['class']) && $rate['class'] == sanitize_title($class)) { echo 'selected="selected"'; } echo '>' . $class . '</option>'; } } echo '</select></td>'; echo '<td><input type="text" value="' . esc_attr($rate['label']) . '" name="tax_label[' . esc_attr($i) . ']" placeholder="' . __('Online Label', 'jigoshop') . '" size="10" /></td>'; echo '<td><select name="tax_country[' . esc_attr($i) . '][]" id="tax_country_' . esc_attr($i) . '" class="tax_select2" multiple="multiple" style="width:220px;">'; if (isset($rate['is_all_states'])) { if (is_array($applied_all_states) && !in_array($rate['country'] . $rate['class'], $applied_all_states)) { $applied_all_states[] = $rate['country'] . $rate['class']; jigoshop_countries::country_dropdown_options($rate['country'], '*', true); //all-states } else { continue; } } else { jigoshop_countries::country_dropdown_options($rate['country'], $rate['state'], true); } echo '</select>'; echo '<button class="select_none button">' . __('None', 'jigoshop') . '</button><button class="button select_all">' . __('All', 'jigoshop') . '</button><button class="button select_us_states">' . __('US States', 'jigoshop') . '</button><button class="button select_europe">' . __('EU States', 'jigoshop') . '</button></td>'; echo '<td><input type="text" value="' . esc_attr($rate['rate']) . '" name="tax_rate[' . esc_attr($i) . ']" placeholder="' . __('Rate (%)', 'jigoshop') . '" size="6" /></td>'; echo '<td><input type="checkbox" name="tax_shipping[' . esc_attr($i) . ']" '; if (isset($rate['shipping']) && $rate['shipping'] == 'yes') { echo 'checked="checked"'; } echo ' /></td>'; echo '<td><input type="checkbox" name="tax_compound[' . esc_attr($i) . ']" '; if (isset($rate['compound']) && $rate['compound'] == 'yes') { echo 'checked="checked"'; } echo ' /></td></tr>'; ?> <script type="text/javascript"> /*<![CDATA[*/ jQuery(function() { jQuery("#tax_country_<?php echo esc_attr($i); ?> ").select2(); }); /*]]>*/ </script><?php } } ?> </tbody> </table> <div><a href="#" class="add button"><?php _e('+ Add Tax Rule', 'jigoshop'); ?> </a></div> </div> <script type="text/javascript"> /*<![CDATA[*/ jQuery(function() { jQuery(document.body).on('click', 'tr.tax_rate .select_none', function(){ jQuery(this).closest('td').find('select option').removeAttr("selected"); jQuery(this).closest('td').find('select.tax_select2').trigger("change"); return false; }); jQuery(document.body).on('click', 'tr.tax_rate .select_all', function(){ jQuery(this).closest('td').find('select option').attr("selected","selected"); jQuery(this).closest('td').find('select.tax_select2').trigger("change"); return false; }); jQuery(document.body).on('click', 'tr.tax_rate .select_us_states', function(){ jQuery(this).closest('td').find('select optgroup[label="<?php _e('United States', 'jigoshop'); ?> "] option').attr("selected","selected"); jQuery(this).closest('td').find('select.tax_select2').trigger("change"); return false; }); jQuery(document.body).on('change', 'tr.tax_rate .options select', function(e){ jQuery(this).trigger("liszt:updated"); jQuery(this).closest('td').find('label').text( jQuery(":selected", this).length + ' ' + '<?php _e('countries/states selected', 'jigoshop'); ?> ' ); }); jQuery(document.body).on('click', 'tr.tax_rate .select_europe', function(e){ jQuery(this).closest('td').find('option[value="BE"],option[value="FR"],option[value="DE"],option[value="IT"],option[value="LU"],option[value="NL"],option[value="DK"],option[value="IE"],option[value="GR"],option[value="PT"],option[value="ES"],option[value="AT"],option[value="FI"],option[value="SE"],option[value="CY"],option[value="CZ"],option[value="EE"],option[value="HU"],option[value="LV"],option[value="LT"],option[value="MT"],option[value="PL"],option[value="SK"],option[value="SI"],option[value="RO"],option[value="BG"],option[value="IM"],option[value="GB"]').attr("selected","selected"); jQuery(this).closest('td').find('select.tax_select2').trigger("change"); return false; }); jQuery(document.body).on('click', '#jigoshop_tax_rates a.add', function() { var size = jQuery('.tax_rate_rules tbody tr').size(); jQuery('<tr class="tax_rate"> \ <td><a href="#" class="remove button">×</a></td> \ <td><select name="tax_classes[' + size + ']" > \ <option value="*"><?php _e('Standard Rate', 'jigoshop'); ?> </option> \ <?php $tax_classes = $_tax->get_tax_classes(); if ($tax_classes) { foreach ($tax_classes as $class) { echo '<option value="' . sanitize_title($class) . '">' . $class . '</option>'; } } ?> \ </select></td> \ <td><input type="text" name="tax_label[' + size + ']" placeholder="<?php _e('Online Label', 'jigoshop'); ?> " size="10" /></td> \ <td><select name="tax_country[' + size + '][]" id="tax_country_' + size +'" multiple="multiple" style="width:220px;"> \ <?php jigoshop_countries::country_dropdown_options('', '', true); ?> </select> \ <button class="select_none button"><?php _e('None', 'jigoshop'); ?> </button> \ <button class="button select_all"><?php _e('All', 'jigoshop'); ?> </button> \ <button class="button select_us_states"><?php _e('US States', 'jigoshop'); ?> </button> \ <button class="button select_europe"><?php _e('EU States', 'jigoshop'); ?> </button></td> \ <td><input type="text" name="tax_rate[' + size + ']" placeholder="<?php _e('Rate (%)', 'jigoshop'); ?> " size="6" /> \ <td><input type="checkbox" name="tax_shipping[' + size + ']" /></td> \ <td><input type="checkbox" name="tax_compound[' + size + ']" /></td> \ </tr>' ).appendTo('#jigoshop_tax_rates .tax_rate_rules tbody'); jQuery('#tax_country_' + size).select2(); jQuery('#tax_country_' + size).addClass("tax_select2"); return false; }); jQuery(document.body).on('click', '#jigoshop_tax_rates a.remove', function(){ var answer = confirm("<?php _e('Delete this rule?', 'jigoshop'); ?> "); if (answer) jQuery(this).parent().parent().remove(); return false; }); }); /*]]>*/ </script> <?php $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * Product data box * * Displays the product data box, tabbed, with several panels covering price, stock etc * * @since 1.0 */ function jigoshop_product_data_box() { global $post, $wpdb, $thepostid; add_action('admin_footer', 'jigoshop_meta_scripts'); wp_nonce_field('jigoshop_save_data', 'jigoshop_meta_nonce'); $thepostid = $post->ID; // Product Type $terms = get_the_terms($thepostid, 'product_type'); $product_type = $terms ? current($terms)->slug : 'simple'; $product_type_selector = apply_filters('jigoshop_product_type_selector', array('simple' => __('Simple', 'jigoshop'), 'downloadable' => __('Downloadable', 'jigoshop'), 'grouped' => __('Grouped', 'jigoshop'), 'virtual' => __('Virtual', 'jigoshop'), 'variable' => __('Variable', 'jigoshop'), 'external' => __('External / Affiliate', 'jigoshop'))); $product_type_select = '<div class="product-type-label">' . __('Product Type', 'jigoshop') . '</div><select id="product-type" name="product-type"><optgroup label="' . __('Product Type', 'jigoshop') . '">'; foreach ($product_type_selector as $value => $label) { $product_type_select .= '<option value="' . $value . '" ' . selected($product_type, $value, false) . '>' . $label . '</option>'; } $product_type_select .= '</optgroup></select><div class="clear"></div>'; ?> <div class="panels"> <span class="jigoshop_product_data_type"><?php echo $product_type_select; ?> </span> <ul class="product_data_tabs tabs" style="display:none;"> <li class="general_tab active"> <a href="#general"><?php _e('General', 'jigoshop'); ?> </a> </li> <li class="advanced_tab"> <a href="#tax"><?php _e('Advanced', 'jigoshop'); ?> </a> </li> <?php if (Jigoshop_Base::get_options()->get('jigoshop_manage_stock') == 'yes') { ?> <li class="inventory_tab"> <a href="#inventory"><?php _e('Inventory', 'jigoshop'); ?> </a> </li> <?php } ?> <li class="attributes_tab"> <a href="#attributes"><?php _e('Attributes', 'jigoshop'); ?> </a> </li> <li class="grouped_tab"> <a href="#grouped"><?php _e('Grouping', 'jigoshop'); ?> </a> </li> <li class="file_tab"> <a href="#files"><?php _e('Download', 'jigoshop'); ?> </a> </li> <?php do_action('jigoshop_product_write_panel_tabs'); ?> <?php do_action('product_write_panel_tabs'); ?> </ul> <div id="general" class="panel jigoshop_options_panel"> <fieldset> <?php // Visibility $args = array('id' => 'product_visibility', 'label' => __('Visibility', 'jigoshop'), 'options' => array('visible' => __('Catalog & Search', 'jigoshop'), 'catalog' => __('Catalog Only', 'jigoshop'), 'search' => __('Search Only', 'jigoshop'), 'hidden' => __('Hidden', 'jigoshop')), 'selected' => get_post_meta($post->ID, 'visibility', true)); echo Jigoshop_Forms::select($args); // Featured $args = array('id' => 'featured', 'label' => __('Featured?', 'jigoshop'), 'desc' => __('Enable this option to feature this product', 'jigoshop'), 'value' => false); echo Jigoshop_Forms::checkbox($args); ?> </fieldset> <fieldset> <?php // SKU if (Jigoshop_Base::get_options()->get('jigoshop_enable_sku') !== 'no') { $args = array('id' => 'sku', 'label' => __('SKU', 'jigoshop'), 'placeholder' => $post->ID); echo Jigoshop_Forms::input($args); } //Brand if (Jigoshop_Base::get_options()->get('jigoshop_enable_brand') !== 'no') { $args = array('id' => 'brand', 'label' => __('Brand', 'jigoshop')); echo Jigoshop_Forms::input($args); } //GTIN if (Jigoshop_Base::get_options()->get('jigoshop_enable_gtin ') !== 'no') { $args = array('id' => 'gtin', 'label' => __('GTIN ', 'jigoshop')); echo Jigoshop_Forms::input($args); } //MPN if (Jigoshop_Base::get_options()->get('jigoshop_enable_mpn') !== 'no') { $args = array('id' => 'mpn', 'label' => __('MPN', 'jigoshop')); echo Jigoshop_Forms::input($args); } ?> </fieldset> <fieldset id="price_fieldset"> <?php // Regular Price $args = array('id' => 'regular_price', 'label' => __('Regular Price', 'jigoshop'), 'after_label' => ' (' . get_jigoshop_currency_symbol() . ')', 'type' => 'number', 'step' => 'any', 'placeholder' => __('Price Not Announced', 'jigoshop')); echo Jigoshop_Forms::input($args); // Sale Price $args = array('id' => 'sale_price', 'label' => __('Sale Price', 'jigoshop'), 'after_label' => ' (' . get_jigoshop_currency_symbol() . __(' or %', 'jigoshop') . ')', 'desc' => '<a href="#" class="sale_schedule">' . __('Schedule', 'jigoshop') . '</a>', 'placeholder' => __('15% or 19.99', 'jigoshop')); echo Jigoshop_Forms::input($args); // Sale Price date range // TODO: Convert this to a helper somehow? $field = array('id' => 'sale_price_dates', 'label' => __('On Sale Between', 'jigoshop')); $sale_price_dates_from = get_post_meta($thepostid, 'sale_price_dates_from', true); $sale_price_dates_to = get_post_meta($thepostid, 'sale_price_dates_to', true); echo '<p class="form-field sale_price_dates_fields">' . __('Current time:', 'jigoshop') . ' ' . current_time('Y-m-d H:i') . '</p>'; echo ' <p class="form-field sale_price_dates_fields"> <label for="' . esc_attr($field['id']) . '_from">' . $field['label'] . '</label> <input type="text" class="short date-pick" name="' . esc_attr($field['id']) . '_from" id="' . esc_attr($field['id']) . '_from" value="'; if ($sale_price_dates_from) { echo date('Y-m-d H:i', $sale_price_dates_from); } echo '" placeholder="' . __('From', 'jigoshop') . ' (' . date('Y-m-d H:i') . ')" maxlength="16" /> <input type="text" class="short date-pick" name="' . esc_attr($field['id']) . '_to" id="' . esc_attr($field['id']) . '_to" value="'; if ($sale_price_dates_to) { echo date('Y-m-d H:i', $sale_price_dates_to); } echo '" placeholder="' . __('To', 'jigoshop') . ' (' . date('Y-m-d H:i') . ')" maxlength="16" /> <a href="#" class="cancel_sale_schedule">' . __('Cancel', 'jigoshop') . '</a> </p>'; ?> <?php do_action('jigoshop_product_pricing_options'); /* allow extensions like sales flash pro to add pricing options */ ?> </fieldset> <fieldset> <?php // External products $args = array('id' => 'external_url', 'label' => __('Product URL', 'jigoshop'), 'placeholder' => __('The URL of the external product (eg. http://www.google.com)', 'jigoshop'), 'extras' => array()); echo Jigoshop_Forms::input($args); ?> </fieldset> <?php do_action('jigoshop_product_general_panel'); ?> </div> <div id="tax" class="panel jigoshop_options_panel"> <fieldset id="tax_fieldset"> <?php // Tax Status $status = get_post_meta($post->ID, 'tax_status', true); if (empty($status)) { $status = Jigoshop_Base::get_options()->get('jigoshop_tax_defaults_status', 'taxable'); } $args = array('id' => 'tax_status', 'label' => __('Tax Status', 'jigoshop'), 'options' => array('taxable' => __('Taxable', 'jigoshop'), 'shipping' => __('Shipping', 'jigoshop'), 'none' => __('None', 'jigoshop')), 'selected' => $status); echo Jigoshop_Forms::select($args); ?> <p class="form_field tax_classes_field"> <label for="tax_classes"><?php _e('Tax Classes', 'jigoshop'); ?> </label> <span class="multiselect short"> <?php $_tax = new jigoshop_tax(); $tax_classes = $_tax->get_tax_classes(); $selections = get_post_meta($post->ID, 'tax_classes', true); if (!is_array($selections)) { $selections = Jigoshop_Base::get_options()->get('jigoshop_tax_defaults_classes', array('*')); } $checked = checked(in_array('*', $selections), true, false); printf('<label %s><input type="checkbox" name="tax_classes[]" value="%s" %s/> %s</label>', !empty($checked) ? 'class="selected"' : '', '*', $checked, __('Standard', 'jigoshop')); if ($tax_classes) { foreach ($tax_classes as $tax_class) { $checked = checked(in_array(sanitize_title($tax_class), $selections), true, false); printf('<label %s><input type="checkbox" name="tax_classes[]" value="%s" %s/> %s</label>', !empty($checked) ? 'class="selected"' : '', sanitize_title($tax_class), $checked, __($tax_class, 'jigoshop')); } } ?> </span> <span class="multiselect-controls"> <a class="check-all" href="#"><?php _e('Check All', 'jigoshop'); ?> </a> | <a class="uncheck-all" href="#"><?php _e('Uncheck All', 'jigoshop'); ?> </a> </span> </p> </fieldset> <?php if (Jigoshop_Base::get_options()->get('jigoshop_enable_weight') !== 'no' || Jigoshop_Base::get_options()->get('jigoshop_enable_dimensions', true) !== 'no') { ?> <fieldset id="form_fieldset"> <?php // Weight if (Jigoshop_Base::get_options()->get('jigoshop_enable_weight') !== 'no') { $args = array('id' => 'weight', 'label' => __('Weight', 'jigoshop'), 'after_label' => ' (' . Jigoshop_Base::get_options()->get('jigoshop_weight_unit') . ')', 'type' => 'number', 'step' => 'any', 'placeholder' => '0.00'); echo Jigoshop_Forms::input($args); } // Dimensions if (Jigoshop_Base::get_options()->get('jigoshop_enable_dimensions', true) !== 'no') { echo ' <p class="form-field dimensions_field"> <label for"product_length">' . __('Dimensions', 'jigoshop') . ' (' . Jigoshop_Base::get_options()->get('jigoshop_dimension_unit') . ')' . '</label> <input type="number" step="any" name="length" class="short" value="' . get_post_meta($thepostid, 'length', true) . '" placeholder="' . __('Length', 'jigoshop') . '" /> <input type="number" step="any" name="width" class="short" value="' . get_post_meta($thepostid, 'width', true) . '" placeholder="' . __('Width', 'jigoshop') . '" /> <input type="number" step="any" name="height" class="short" value="' . get_post_meta($thepostid, 'height', true) . '" placeholder="' . __('Height', 'jigoshop') . '" /> </p> '; } ?> </fieldset> <?php } ?> <fieldset> <?php // Customizable $args = array('id' => 'product_customize', 'label' => __('Can be personalized', 'jigoshop'), 'options' => array('no' => __('No', 'jigoshop'), 'yes' => __('Yes', 'jigoshop')), 'selected' => get_post_meta($post->ID, 'customizable', true)); echo Jigoshop_Forms::select($args); // Customizable length $args = array('id' => 'customized_length', 'label' => __('Personalized Characters', 'jigoshop'), 'type' => 'number', 'value' => get_post_meta($post->ID, 'customized_length', true), 'placeholder' => __('Leave blank for unlimited', 'jigoshop')); echo Jigoshop_Forms::input($args); ?> </fieldset> <?php do_action('jigoshop_product_tax_panel'); ?> </div> <?php if (Jigoshop_Base::get_options()->get('jigoshop_manage_stock') == 'yes') { ?> <div id="inventory" class="panel jigoshop_options_panel"> <fieldset> <?php // manage stock $args = array('id' => 'manage_stock', 'label' => __('Manage Stock?', 'jigoshop'), 'desc' => __('Handle stock for me', 'jigoshop'), 'value' => false); echo Jigoshop_Forms::checkbox($args); ?> </fieldset> <fieldset> <?php // Stock Status // TODO: These values should be true/false $args = array('id' => 'stock_status', 'label' => __('Stock Status', 'jigoshop'), 'options' => array('instock' => __('In Stock', 'jigoshop'), 'outofstock' => __('Out of Stock', 'jigoshop'))); echo Jigoshop_Forms::select($args); echo '<div class="stock_fields">'; // Stock // TODO: Missing default value of 0 $args = array('id' => 'stock', 'label' => __('Stock Quantity', 'jigoshop'), 'type' => 'number'); echo Jigoshop_Forms::input($args); // Backorders $args = array('id' => 'backorders', 'label' => __('Allow Backorders?', 'jigoshop'), 'options' => array('no' => __('Do not allow', 'jigoshop'), 'notify' => __('Allow, but notify customer', 'jigoshop'), 'yes' => __('Allow', 'jigoshop'))); echo Jigoshop_Forms::select($args); echo '</div>'; ?> </fieldset> <?php do_action('jigoshop_product_inventory_panel'); ?> </div> <?php } ?> <div id="attributes" class="panel"> <?php do_action('jigoshop_attributes_display'); ?> </div> <div id="grouped" class="panel jigoshop_options_panel"> <?php // Grouped Products // TODO: Needs refactoring & a bit of love $posts_in = (array) get_objects_in_term(get_term_by('slug', 'grouped', 'product_type')->term_id, 'product_type'); $posts_in = array_unique($posts_in); if ((bool) $posts_in) { $args = array('post_type' => 'product', 'post_status' => 'publish', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'asc', 'post_parent' => 0, 'include' => $posts_in); $grouped_products = get_posts($args); $options = array(null => '– Pick a Product Group –'); if ($grouped_products) { foreach ($grouped_products as $product) { if ($product->ID == $post->ID) { continue; } $options[$product->ID] = $product->post_title; } } // Only echo the form if we have grouped products $args = array('id' => 'parent_id', 'label' => __('Product Group', 'jigoshop'), 'options' => $options, 'selected' => $post->post_parent); echo Jigoshop_Forms::select($args); } // Ordering $args = array('id' => 'menu_order', 'label' => __('Sort Order', 'jigoshop'), 'type' => 'number', 'value' => $post->menu_order); echo Jigoshop_Forms::input($args); $args = array('id' => 'variation_order', 'label' => __('Variation Order', 'jigoshop'), 'options' => array('asort' => __('By name ascending', 'jigoshop'), 'arsort' => __('By name descending', 'jigoshop'), 'ksort' => __('From first to last key', 'jigoshop'), 'krsort' => __('From last to first key', 'jigoshop'), 'shuffle' => __('Random', 'jigoshop')), 'selected' => get_post_meta($post->ID, 'variation_order', true)); echo Jigoshop_Forms::select($args); ?> <?php do_action('jigoshop_product_grouped_panel'); ?> </div> <div id="files" class="panel jigoshop_options_panel"> <fieldset> <?php // DOWNLOADABLE OPTIONS // File URL // TODO: Refactor this into a helper $file_path = get_post_meta($post->ID, 'file_path', true); $field = array('id' => 'file_path', 'label' => __('File Path', 'jigoshop')); echo '<p class="form-field"><label for="' . esc_attr($field['id']) . '">' . $field['label'] . ':</label> <input type="text" class="file_path" name="' . esc_attr($field['id']) . '" id="' . esc_attr($field['id']) . '" value="' . esc_attr($file_path) . '" placeholder="' . site_url() . '" /> <input type="button" class="upload_file_button button" data-postid="' . esc_attr($post->ID) . '" value="' . __('Upload a file', 'jigoshop') . '" /> </p>'; // Download Limit $args = array('id' => 'download_limit', 'label' => __('Download Limit', 'jigoshop'), 'type' => 'number', 'desc' => __('Leave blank for unlimited re-downloads', 'jigoshop')); echo Jigoshop_Forms::input($args); do_action('additional_downloadable_product_type_options'); ?> </fieldset> <?php do_action('jigoshop_product_files_panel'); ?> </div> <?php do_action('jigoshop_product_write_panels'); ?> <?php do_action('product_write_panels'); ?> </div> <?php }
/** * Validate the checkout */ public function validate_checkout() { if (jigoshop_cart::is_empty()) { jigoshop::add_error(sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage →</a>', 'jigoshop'), home_url())); } // Process Discount Codes if (!empty($_POST['coupon_code'])) { $coupon = sanitize_title($_POST['coupon_code']); jigoshop_cart::add_discount($coupon); } foreach (jigoshop_cart::get_coupons() as $coupon) { jigoshop_cart::is_valid_coupon($coupon); } // Checkout fields $this->posted['shipping_method'] = ''; $this->posted['shipping_service'] = ''; if (isset($_POST['shipping_method'])) { $shipping_method = jigowatt_clean($_POST['shipping_method']); $shipping_data = explode(':', $shipping_method); $this->posted['shipping_method'] = $shipping_data[0]; $this->posted['shipping_service'] = $shipping_data[1]; } $this->posted['shiptobilling'] = isset($_POST['shiptobilling']) ? jigowatt_clean($_POST['shiptobilling']) : ''; $this->posted['payment_method'] = isset($_POST['payment_method']) ? jigowatt_clean($_POST['payment_method']) : ''; $this->posted['order_comments'] = isset($_POST['order_comments']) ? jigowatt_clean($_POST['order_comments']) : ''; $this->posted['terms'] = isset($_POST['terms']) ? jigowatt_clean($_POST['terms']) : ''; $this->posted['create_account'] = isset($_POST['create_account']) ? jigowatt_clean($_POST['create_account']) : ''; $this->posted['account_username'] = isset($_POST['account_username']) ? jigowatt_clean($_POST['account_username']) : ''; $this->posted['account_password'] = isset($_POST['account_password']) ? jigowatt_clean($_POST['account_password']) : ''; $this->posted['account_password_2'] = isset($_POST['account_password_2']) ? jigowatt_clean($_POST['account_password_2']) : ''; if (jigoshop_cart::get_total(false) == 0) { $this->posted['payment_method'] = 'no_payment'; } // establish customer billing and shipping locations if (jigoshop_cart::ship_to_billing_address_only()) { $this->posted['shiptobilling'] = 'true'; } $country = isset($_POST['billing_country']) ? jigowatt_clean($_POST['billing_country']) : ''; $state = isset($_POST['billing_state']) ? jigowatt_clean($_POST['billing_state']) : ''; $allowed_countries = Jigoshop_Base::get_options()->get('jigoshop_allowed_countries'); if ($allowed_countries === 'specific') { $specific_countries = Jigoshop_Base::get_options()->get('jigoshop_specific_allowed_countries'); if (!in_array($country, $specific_countries)) { jigoshop::add_error(__('Invalid billing country.', 'jigoshop')); return; } } if (jigoshop_countries::country_has_states($country)) { $states = jigoshop_countries::get_states($country); if (!in_array($state, array_keys($states))) { jigoshop::add_error(__('Invalid billing state.', 'jigoshop')); return; } } $postcode = isset($_POST['billing_postcode']) ? jigowatt_clean($_POST['billing_postcode']) : ''; $ship_to_billing = Jigoshop_Base::get_options()->get('jigoshop_ship_to_billing_address_only') == 'yes'; jigoshop_customer::set_location($country, $state, $postcode); if (Jigoshop_Base::get_options()->get('jigoshop_calc_shipping') == 'yes') { if ($ship_to_billing || !empty($_POST['shiptobilling'])) { jigoshop_customer::set_shipping_location($country, $state, $postcode); } else { $country = isset($_POST['shipping_country']) ? jigowatt_clean($_POST['shipping_country']) : ''; $state = isset($_POST['shipping_state']) ? jigowatt_clean($_POST['shipping_state']) : ''; $postcode = isset($_POST['shipping_postcode']) ? jigowatt_clean($_POST['shipping_postcode']) : ''; if ($allowed_countries === 'specific') { $specific_countries = Jigoshop_Base::get_options()->get('jigoshop_specific_allowed_countries'); if (!in_array($country, $specific_countries)) { jigoshop::add_error(__('Invalid shipping country.', 'jigoshop')); return; } } if (jigoshop_countries::country_has_states($country)) { $states = jigoshop_countries::get_states($country); if (!in_array($state, array_keys($states))) { jigoshop::add_error(__('Invalid shipping state.', 'jigoshop')); return; } } jigoshop_customer::set_shipping_location($country, $state, $postcode); } } // Billing Information foreach ($this->billing_fields as $field) { $field = apply_filters('jigoshop_billing_field', $field); $this->posted[$field['name']] = isset($_POST[$field['name']]) ? jigowatt_clean($_POST[$field['name']]) : ''; // Format if (isset($field['format'])) { switch ($field['format']) { case 'postcode': $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break; } } // Required if ($field['name'] == 'billing_state' && jigoshop_customer::has_valid_shipping_state()) { $field['required'] = false; } if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) { jigoshop::add_error($field['label'] . __(' (billing) is a required field.', 'jigoshop')); } if ($field['name'] == 'billing_euvatno') { $vatno = isset($this->posted['billing_euvatno']) ? $this->posted['billing_euvatno'] : ''; $vatno = str_replace(' ', '', $vatno); $country = jigoshop_tax::get_customer_country(); // strip any country code from the beginning of the number if (strpos($vatno, $country) === 0) { $vatno = substr($vatno, strlen($country)); } if ($vatno != '') { $url = 'http://isvat.appspot.com/' . $country . '/' . $vatno . '/'; $httpRequest = curl_init(); curl_setopt($httpRequest, CURLOPT_FAILONERROR, true); curl_setopt($httpRequest, CURLOPT_RETURNTRANSFER, true); curl_setopt($httpRequest, CURLOPT_HEADER, false); curl_setopt($httpRequest, CURLOPT_URL, $url); $result = curl_exec($httpRequest); curl_close($httpRequest); if ($result === 'false') { jigoshop_log('EU VAT validation error with URL: ' . $url); jigoshop::add_error($field['label'] . __(' (billing) is not a valid VAT Number. Leave it blank to disable VAT validation. (VAT may be charged depending on your location)', 'jigoshop')); } else { $this->valid_euvatno = jigoshop_countries::get_base_country() != jigoshop_tax::get_customer_country() && jigoshop_countries::is_eu_country(jigoshop_tax::get_customer_country()); } } } // Validation if (isset($field['validate']) && !empty($this->posted[$field['name']])) { switch ($field['validate']) { case 'phone': if (!jigoshop_validation::is_phone($this->posted[$field['name']])) { jigoshop::add_error($field['label'] . __(' (billing) is not a valid number.', 'jigoshop')); } break; case 'email': if (!jigoshop_validation::is_email($this->posted[$field['name']])) { jigoshop::add_error($field['label'] . __(' (billing) is not a valid email address.', 'jigoshop')); } break; case 'postcode': if (!jigoshop_validation::is_postcode($this->posted[$field['name']], $_POST['billing_country'])) { jigoshop::add_error($field['label'] . __(' (billing) is not a valid postcode/ZIP.', 'jigoshop')); } else { $this->posted[$field['name']] = jigoshop_validation::format_postcode($this->posted[$field['name']], $_POST['billing_country']); } break; } } } // Shipping Information if (jigoshop_shipping::is_enabled() && !jigoshop_cart::ship_to_billing_address_only() && empty($this->posted['shiptobilling'])) { foreach ($this->shipping_fields as $field) { $field = apply_filters('jigoshop_shipping_field', $field); if (isset($_POST[$field['name']])) { $this->posted[$field['name']] = jigowatt_clean($_POST[$field['name']]); } else { $this->posted[$field['name']] = ''; } // Format if (isset($field['format'])) { switch ($field['format']) { case 'postcode': $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break; } } // Required if ($field['name'] == 'shipping_state' && jigoshop_customer::has_valid_shipping_state()) { $field['required'] = false; } if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) { jigoshop::add_error($field['label'] . __(' (shipping) is a required field.', 'jigoshop')); } // Validation if (isset($field['validate']) && !empty($this->posted[$field['name']])) { switch ($field['validate']) { case 'postcode': if (!jigoshop_validation::is_postcode($this->posted[$field['name']], $country)) { jigoshop::add_error($field['label'] . __(' (shipping) is not a valid postcode/ZIP.', 'jigoshop')); } else { $this->posted[$field['name']] = jigoshop_validation::format_postcode($this->posted[$field['name']], $country); } break; } } } } if ($this->must_register && empty($this->posted['create_account'])) { jigoshop::add_error(__('Sorry, you must agree to creating an account', 'jigoshop')); } if ($this->must_register || empty($user_id) && $this->posted['create_account']) { if (!$this->show_signup) { jigoshop::add_error(__('Sorry, the shop owner has disabled guest purchases.', 'jigoshop')); } if (empty($this->posted['account_username'])) { jigoshop::add_error(__('Please enter an account username.', 'jigoshop')); } if (empty($this->posted['account_password'])) { jigoshop::add_error(__('Please enter an account password.', 'jigoshop')); } if ($this->posted['account_password_2'] !== $this->posted['account_password']) { jigoshop::add_error(__('Passwords do not match.', 'jigoshop')); } // Check the username if (!validate_username($this->posted['account_username'])) { jigoshop::add_error(__('Invalid email/username.', 'jigoshop')); } elseif (username_exists($this->posted['account_username'])) { jigoshop::add_error(__('An account is already registered with that username. Please choose another.', 'jigoshop')); } // Check the e-mail address if (email_exists($this->posted['billing_email'])) { jigoshop::add_error(__('An account is already registered with your email address. Please login.', 'jigoshop')); } } // Terms if (!isset($_POST['update_totals']) && empty($this->posted['terms']) && jigoshop_get_page_id('terms') > 0) { jigoshop::add_error(__('You must accept our Terms & Conditions.', 'jigoshop')); } if (jigoshop_cart::needs_shipping()) { // Shipping Method $available_methods = jigoshop_shipping::get_available_shipping_methods(); if (!isset($available_methods[$this->posted['shipping_method']])) { jigoshop::add_error(__('Invalid shipping method.', 'jigoshop')); } } }
/** * Product data box * * Displays the product data box, tabbed, with several panels covering price, stock etc * * @since 1.0 */ function jigoshop_product_data_box() { global $post, $wpdb, $thepostid; add_action('admin_footer', 'jigoshop_meta_scripts'); wp_nonce_field( 'jigoshop_save_data', 'jigoshop_meta_nonce' ); $data = (array) maybe_unserialize( get_post_meta($post->ID, 'product_data', true) ); $featured = (string) get_post_meta( $post->ID, 'featured', true ); $visibility = (string) get_post_meta( $post->ID, 'visibility', true); if (!isset($data['weight'])) $data['weight'] = ''; if (!isset($data['regular_price'])) $data['regular_price'] = ''; if (!isset($data['sale_price'])) $data['sale_price'] = ''; $thepostid = $post->ID; ?> <div class="panel-wrap product_data"> <ul class="product_data_tabs tabs" style="display:none;"> <li class="active"><a href="#general_product_data"><?php _e('General', 'jigoshop'); ?></a></li> <li class="pricing_tab"><a href="#pricing_product_data"><?php _e('Pricing', 'jigoshop'); ?></a></li> <?php if (get_option('jigoshop_manage_stock')=='yes') : ?><li class="inventory_tab"><a href="#inventory_product_data"><?php _e('Inventory', 'jigoshop'); ?></a></li><?php endif; ?> <li><a href="#jigoshop_attributes"><?php _e('Attributes', 'jigoshop'); ?></a></li> <?php do_action('product_write_panel_tabs'); ?> </ul> <div id="general_product_data" class="panel jigoshop_options_panel"><?php // Product Type if ($terms = wp_get_object_terms( $thepostid, 'product_type' )) $product_type = current($terms)->slug; else $product_type = 'simple'; $field = array( 'id' => 'product-type', 'label' => __('Product Type', 'jigoshop') ); echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].' <em class="req" title="'.__('Required', 'jigoshop') . '">*</em></label><select id="'.$field['id'].'" name="'.$field['id'].'">'; echo '<option value="simple" '; if ($product_type=='simple') echo 'selected="selected"'; echo '>'.__('Simple','jigoshop').'</option>'; do_action('product_type_selector', $product_type); echo '</select></p>'; // Summary echo '<p class="form-field"><label for="excerpt">' . __('Summary', 'jigoshop') . ':</label> <textarea name="excerpt" id="excerpt" placeholder="' . __('Add a summary for your product – this is a quick description to encourage users to view the product.', 'jigoshop') . '">'.esc_html( $post->post_excerpt ).'</textarea></p>'; // SKU $field = array( 'id' => 'sku', 'label' => __('SKU', 'jigoshop') ); $SKU = get_post_meta($thepostid, 'SKU', true); if( get_option('jigoshop_enable_sku', true) !== 'no' ) : echo '<p class="form-field"> <label for="'.$field['id'].'">'.$field['label'].':</label> <input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$SKU.'" /> <span class="description">' . __('Leave blank to use product ID', 'jigoshop') . '</span></p>'; else: echo '<input type="hidden" name="'.$field['id'].'" value="'.$SKU.'" />'; endif; // Weight $field = array( 'id' => 'weight', 'label' => __('Weight', 'jigoshop') . ' ('.get_option('jigoshop_weight_unit').'):' ); if( get_option('jigoshop_enable_weight', true) !== 'no' ) : echo '<p class="form-field"> <label for="'.$field['id'].'">'.$field['label'].'</label> <input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$data[$field['id']].'" placeholder="0.00" /></p>'; else: echo '<input type="hidden" name="'.$field['id'].'" value="'.$data[$field['id']].'" />'; endif; // Featured $field = array( 'id' => 'featured', 'label' => __('Featured?', 'jigoshop') ); echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].'</label><select name="'.$field['id'].'">'; echo '<option value="no" '; if (isset($featured) && $featured=='no') echo 'selected="selected"'; echo '>' . __('No', 'jigoshop') . '</option>'; echo '<option value="yes" '; if (isset($featured) && $featured=='yes') echo 'selected="selected"'; echo '>' . __('Yes', 'jigoshop') . '</option>'; echo '</select></p>'; // Visibility $field = array( 'id' => 'visibility', 'label' => __('Visibility', 'jigoshop') ); echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].':</label><select name="'.$field['id'].'">'; echo '<option value="visible" '; if (isset($visibility) && $visibility=='visible') echo 'selected="selected"'; echo '>' . __('Catalog & Search', 'jigoshop') . '</option>'; echo '<option value="catalog" '; if (isset($visibility) && $visibility=='catalog') echo 'selected="selected"'; echo '>' . __('Catalog', 'jigoshop') . '</option>'; echo '<option value="search" '; if (isset($visibility) && $visibility=='search') echo 'selected="selected"'; echo '>' . __('Search', 'jigoshop') . '</option>'; echo '<option value="hidden" '; if (isset($visibility) && $visibility=='hidden') echo 'selected="selected"'; echo '>' . __('Hidden', 'jigoshop') . '</option>'; echo '</select></p>'; ?> </div> <div id="pricing_product_data" class="panel jigoshop_options_panel"> <?php // Price $field = array( 'id' => 'regular_price', 'label' => __('Regular Price', 'jigoshop') . ' ('.get_jigoshop_currency_symbol().'):' ); echo ' <p class="form-field"> <label for="'.$field['id'].'">'.$field['label'].'</label> <input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$data[$field['id']].'" placeholder="0.00" /></p>'; // Special Price $field = array( 'id' => 'sale_price', 'label' => __('Sale Price', 'jigoshop') . ' ('.get_jigoshop_currency_symbol().'):' ); echo ' <p class="form-field"> <label for="'.$field['id'].'">'.$field['label'].'</label> <input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$data[$field['id']].'" placeholder="0.00" /></p>'; // Special Price date range $field = array( 'id' => 'sale_price_dates', 'label' => __('Sale Price Dates', 'jigoshop') ); $sale_price_dates_from = get_post_meta($thepostid, 'sale_price_dates_from', true); $sale_price_dates_to = get_post_meta($thepostid, 'sale_price_dates_to', true); echo ' <p class="form-field"> <label for="'.$field['id'].'_from">'.$field['label'].':</label> <input type="text" class="short date-pick" name="'.$field['id'].'_from" id="'.$field['id'].'_from" value="'; if ($sale_price_dates_from) echo date('Y-m-d', $sale_price_dates_from); echo '" placeholder="' . __('From…', 'jigoshop') . '" maxlength="10" /> <input type="text" class="short date-pick" name="'.$field['id'].'_to" id="'.$field['id'].'_to" value="'; if ($sale_price_dates_to) echo date('Y-m-d', $sale_price_dates_to); echo '" placeholder="' . __('To…', 'jigoshop') . '" maxlength="10" /> <span class="description">' . __('Date format', 'jigoshop') . ': <code>YYYY-MM-DD</code></span> </p>'; // Tax $_tax = new jigoshop_tax(); $field = array( 'id' => 'tax_status', 'label' => __('Tax Status', 'jigoshop') ); echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].':</label><select name="'.$field['id'].'">'; echo '<option value="taxable" '; if (isset($data[$field['id']]) && $data[$field['id']]=='taxable') echo 'selected="selected"'; echo '>' . __('Taxable', 'jigoshop') . '</option>'; echo '<option value="shipping" '; if (isset($data[$field['id']]) && $data[$field['id']]=='shipping') echo 'selected="selected"'; echo '>' . __('Shipping only', 'jigoshop') . '</option>'; echo '<option value="none" '; if (isset($data[$field['id']]) && $data[$field['id']]=='none') echo 'selected="selected"'; echo '>' . __('None', 'jigoshop') . '</option>'; echo '</select></p>'; $field = array( 'id' => 'tax_class', 'label' => __('Tax Class', 'jigoshop') ); echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].':</label><select name="'.$field['id'].'">'; echo '<option value="" '; if (isset($data[$field['id']]) && $data[$field['id']]=='') echo 'selected="selected"'; echo '>'.__('Standard', 'jigoshop').'</option>'; $tax_classes = $_tax->get_tax_classes(); if ($tax_classes) foreach ($tax_classes as $class) : echo '<option value="'.sanitize_title($class).'" '; if (isset($data[$field['id']]) && $data[$field['id']]==sanitize_title($class)) echo 'selected="selected"'; echo '>'.$class.'</option>'; endforeach; echo '</select></p>'; ?> </div> <?php if (get_option('jigoshop_manage_stock')=='yes') : ?> <div id="inventory_product_data" class="panel jigoshop_options_panel"> <?php // manage stock $field = array( 'id' => 'manage_stock', 'label' => __('Manage stock?', 'jigoshop') ); echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].' <em class="req" title="' .__('Required', 'jigoshop') . '">*</em></label><input type="checkbox" class="checkbox" name="'.$field['id'].'" id="'.$field['id'].'"'; if (isset($data[$field['id']]) && $data[$field['id']]=='yes') echo 'checked="checked"'; echo ' /></p>'; // Stock status $field = array( 'id' => 'stock_status', 'label' => 'Stock status:' ); echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].' <em class="req" title="'.__('Required', 'jigoshop') . '">*</em></label><select name="'.$field['id'].'">'; echo '<option value="instock" '; if (isset($data[$field['id']]) && $data[$field['id']]=='instock') echo 'selected="selected"'; echo '>In stock</option>'; echo '<option value="outofstock" '; if (isset($data[$field['id']]) && $data[$field['id']]=='outofstock') echo 'selected="selected"'; echo '>Out of stock</option>'; echo '</select></p>'; echo '<div class="stock_fields">'; // Stock $field = array( 'id' => 'stock', 'label' => __('Stock Qty', 'jigoshop') ); echo ' <p class="form-field"> <label for="'.$field['id'].'">'.$field['label'].': <em class="req" title="'.__('Required', 'jigoshop') . '">*</em></label> <input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'; $stock = get_post_meta($post->ID, 'stock', true); if (!$stock) $stock = 0; echo $stock; echo '" /> </p>'; // Backorders? $field = array( 'id' => 'backorders', 'label' => __('Allow Backorders?', 'jigoshop') ); echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].' <em class="req" title="'.__('Required', 'jigoshop') . '">*</em></label><select name="'.$field['id'].'">'; echo '<option value="no" '; if (isset($data[$field['id']]) && $data[$field['id']]=='no') echo 'selected="selected"'; echo '>' . __('Do not allow', 'jigoshop') . '</option>'; echo '<option value="notify" '; if (isset($data[$field['id']]) && $data[$field['id']]=='notify') echo 'selected="selected"'; echo '>' . __('Allow, but notify customer', 'jigoshop') . '</option>'; echo '<option value="yes" '; if (isset($data[$field['id']]) && $data[$field['id']]=='yes') echo 'selected="selected"'; echo '>' . __('Allow', 'jigoshop') . '</option>'; echo '</select></p>'; echo '</div>'; ?> </div> <?php endif; ?> <div id="jigoshop_attributes" class="panel"> <div class="jigoshop_attributes_wrapper"> <table cellpadding="0" cellspacing="0" class="jigoshop_attributes"> <thead> <tr> <th class="center" width="60"><?php _e('Order', 'jigoshop'); ?></th> <th width="180"><?php _e('Name', 'jigoshop'); ?></th> <th><?php _e('Value', 'jigoshop'); ?></th> <th class="center" width="1%"><?php _e('Visible?', 'jigoshop'); ?></th> <!--th class="center" width="1%"><?php _e('Variation?', 'jigoshop'); ?></th--> <th class="center" width="1%"><?php _e('Remove', 'jigoshop'); ?></th> </tr> </thead> <tbody id="attributes_list"> <?php $attribute_taxonomies = jigoshop::$attribute_taxonomies; $attributes = maybe_unserialize( get_post_meta($post->ID, 'product_attributes', true) ); $i = -1; // Taxonomies if ( $attribute_taxonomies ) : foreach ($attribute_taxonomies as $tax) : $i++; $attribute_nicename = strtolower(sanitize_title($tax->attribute_name)); if (isset($attributes[$attribute_nicename])) $attribute = $attributes[$attribute_nicename]; if (isset($attribute['visible']) && $attribute['visible']=='yes') $checked = 'checked="checked"'; else $checked = ''; if (isset($attribute['variation']) && $attribute['variation']=='yes') $checked2 = 'checked="checked"'; else $checked2 = ''; $values = wp_get_post_terms( $thepostid, 'pa_'.strtolower(sanitize_title($tax->attribute_name)) ); $value = array(); if (!is_wp_error($values) && $values) : foreach ($values as $v) : $value[] = $v->slug; endforeach; endif; ?><tr class="taxonomy <?php echo strtolower(sanitize_title($tax->attribute_name)); ?>" rel="<?php if (isset($attribute['position'])) echo $attribute['position']; else echo '0'; ?>" <?php if (!$value || sizeof($value)==0) echo 'style="display:none"'; ?>> <td class="center"> <button type="button" class="move_up button">↑</button><button type="button" class="move_down button">↓</button> <input type="hidden" name="attribute_position[<?php echo $i; ?>]" class="attribute_position" value="<?php if (isset($attribute['position'])) echo $attribute['position']; else echo '0'; ?>" /> </td> <td class="name"> <?php echo $tax->attribute_name; ?> <input type="hidden" name="attribute_names[<?php echo $i; ?>]" value="<?php echo $tax->attribute_name; ?>" /> <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?>]" value="1" /> </td> <td> <?php if ($tax->attribute_type=="select" || $tax->attribute_type=="multiselect") : ?> <select <?php if ($tax->attribute_type=="multiselect") echo 'multiple="multiple" class="multiselect" name="attribute_values['.$i.'][]"'; else echo 'name="attribute_values['.$i.']"'; ?>> <?php if ($tax->attribute_type=="select") : ?><option value=""><?php _e('Choose an option…', 'jigoshop'); ?></option><?php endif; ?> <?php if (taxonomy_exists('pa_'.strtolower(sanitize_title($tax->attribute_name)))) : $terms = get_terms( 'pa_'.strtolower(sanitize_title($tax->attribute_name)), 'orderby=name&hide_empty=0' ); if ($terms) : foreach ($terms as $term) : echo '<option value="'.$term->name.'" '; if (in_array($term->slug, $value)) echo 'selected="selected"'; echo '>'.$term->name.'</option>'; endforeach; endif; endif; ?> </select> <?php elseif ($tax->attribute_type=="text") : ?> <input type="text" name="attribute_values[<?php echo $i; ?>]" value="<?php if (isset($attribute['value'])) echo $attribute['value']; ?>" placeholder="<?php _e('Comma separate terms', 'jigoshop'); ?>" /> <?php endif; ?> </td> <td class="center"><input type="checkbox" <?php echo $checked; ?> name="attribute_visibility[<?php echo $i; ?>]" value="1" /></td> <!--td class="center"><input type="checkbox" <?php echo $checked2; ?> name="attribute_variation[<?php echo $i; ?>]" value="1" /></td--> <td class="center"><button type="button" class="hide_row button">×</button></td> </tr><?php endforeach; endif; // Attributes if ($attributes && sizeof($attributes)>0) foreach ($attributes as $attribute) : if (isset($attribute['is_taxonomy']) && $attribute['is_taxonomy']=='yes') continue; $i++; if (isset($attribute['visible']) && $attribute['visible']=='yes') $checked = 'checked="checked"'; else $checked = ''; if (isset($attribute['variation']) && $attribute['variation']=='yes') $checked2 = 'checked="checked"'; else $checked2 = ''; ?><tr rel="<?php if (isset($attribute['position'])) echo $attribute['position']; else echo '0'; ?>"> <td class="center"> <button type="button" class="move_up button">↑</button><button type="button" class="move_down button">↓</button> <input type="hidden" name="attribute_position[<?php echo $i; ?>]" class="attribute_position" value="<?php if (isset($attribute['position'])) echo $attribute['position']; else echo '0'; ?>" /> </td> <td> <input type="text" name="attribute_names[<?php echo $i; ?>]" value="<?php echo $attribute['name']; ?>" /> <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?>]" value="0" /> </td> <td><input type="text" name="attribute_values[<?php echo $i; ?>]" value="<?php echo $attribute['value']; ?>" /></td> <td class="center"><input type="checkbox" <?php echo $checked; ?> name="attribute_visibility[<?php echo $i; ?>]" value="1" /></td> <!--td class="center"><input type="checkbox" <?php echo $checked2; ?> name="attribute_variation[<?php echo $i; ?>]" value="1" /></td--> <td class="center"><button type="button" class="remove_row button">×</button></td> </tr><?php endforeach; ?> </tbody> </table> </div> <button type="button" class="button button-primary add_attribute"><?php _e('Add', 'jigoshop'); ?></button> <select name="attribute_taxonomy" class="attribute_taxonomy"> <option value=""><?php _e('Custom product attribute', 'jigoshop'); ?></option> <?php if ( $attribute_taxonomies ) : foreach ($attribute_taxonomies as $tax) : echo '<option value="'.strtolower(sanitize_title($tax->attribute_name)).'">'.$tax->attribute_name.'</option>'; endforeach; endif; ?> </select> <div class="clear"></div> </div> <?php do_action('product_write_panels'); ?> </div> <?php }
public function display_default_tax_classes() { $tax = new jigoshop_tax(); $classes = $tax->get_tax_classes(); $defaults = Jigoshop_Base::get_options()->get('jigoshop_tax_defaults_classes', array('*')); ob_start(); //We don't want any notices here. $old_status = error_reporting(0); echo Jigoshop_Forms::checkbox(array('id' => 'jigoshop_tax_defaults_class_standard', 'name' => 'jigoshop_tax_defaults_classes[*]', 'label' => __('Standard', 'jigoshop'), 'value' => in_array('*', $defaults))); foreach ($classes as $class) { $value = sanitize_title($class); echo Jigoshop_Forms::checkbox(array('id' => 'jigoshop_tax_defaults_class_' . $value, 'name' => 'jigoshop_tax_defaults_classes[' . $value . ']', 'label' => __($class, 'jigoshop'), 'value' => in_array($value, $defaults))); } error_reporting($old_status); return ob_get_clean(); }
function jigoshop_add_order_item() { $jigoshop_options = Jigoshop_Base::get_options(); check_ajax_referer('add-order-item', 'security'); global $wpdb; $item_to_add = trim(stripslashes($_POST['item_to_add'])); $post = ''; // Find the item if (is_numeric($item_to_add)) { $post = get_post($item_to_add); } if (!$post || $post->post_type !== 'product' && $post->post_type !== 'product_variation') { $post_id = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT post_id\n\t\t\tFROM {$wpdb->posts}\n\t\t\tLEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)\n\t\t\tWHERE {$wpdb->postmeta}.meta_key = 'SKU'\n\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\tAND {$wpdb->posts}.post_type = 'shop_product'\n\t\t\tAND {$wpdb->postmeta}.meta_value = %s\n\t\t\tLIMIT 1\n\t\t", $item_to_add)); $post = get_post($post_id); } if (!$post || $post->post_type !== 'product' && $post->post_type !== 'product_variation') { die; } if ($post->post_type == "product") { $_product = new jigoshop_product($post->ID); } else { $_product = new jigoshop_product_variation($post->ID); } $loop = 0; ?> <tr class="item"> <?php do_action('jigoshop_admin_order_item_before_prod_id', intval($_POST['item_no'])); ?> <td class="product-id">#<?php echo $_product->id; ?> </td> <td class="variation-id"><?php if (isset($_product->variation_id)) { echo $_product->variation_id; } else { echo '-'; } ?> </td> <td class="product-sku"><?php if ($_product->sku) { echo $_product->sku; } ?> </td> <td class="name"><a href="<?php echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit')); ?> "><?php echo $_product->get_title(); ?> </a></td> <td class="variation"><?php if (isset($_product->variation_data)) { echo jigoshop_get_formatted_variation($_product, array(), true); } else { echo '-'; } ?> </td> <!--<td> <table class="meta" cellspacing="0"> <tfoot> <tr> <td colspan="3"><button class="add_meta button"><?php _e('Add meta', 'jigoshop'); ?> </button></td> </tr> </tfoot> <tbody></tbody> </table> </td>--> <?php do_action('jigoshop_admin_order_item_values', $_product, array(), 0); ?> <td class="quantity"><input type="text" name="item_quantity[]" placeholder="<?php _e('Quantity e.g. 2', 'jigoshop'); ?> " value="1" /></td> <td class="cost"><input type="text" name="item_cost[]" placeholder="<?php _e('Cost per unit ex. tax e.g. 2.99', 'jigoshop'); ?> " value="<?php echo esc_attr($jigoshop_options->get('jigoshop_prices_include_tax') == 'yes' ? $_product->get_price_excluding_tax() : $_product->get_price()); ?> " /></td> <td class="tax"><input type="text" name="item_tax_rate[]" placeholder="<?php _e('Tax Rate e.g. 20.0000', 'jigoshop'); ?> " value="<?php echo esc_attr(jigoshop_tax::calculate_total_tax_rate($_product->get_tax_base_rate())); ?> " /></td> <td class="center"> <input type="hidden" name="item_id[]" value="<?php echo esc_attr($_product->id); ?> " /> <input type="hidden" name="item_name[]" value="<?php echo esc_attr($_product->get_title()); ?> " /> <input type="hidden" name="item_variation_id[]" value="<?php if ($_product instanceof jigoshop_product_variation) { echo esc_attr($_product->variation_id); } else { echo ''; } ?> " /> <button type="button" class="remove_row button">×</button> </td> </tr> <?php // Quit out die; }
/** * Execute changes made in Jigoshop 1.2.0 * * @since 1.2 */ function jigoshop_upgrade_120() { // update orders $args = array( 'post_type' => 'shop_order', 'numberposts' => -1, 'post_status' => 'publish' ); $posts = get_posts( $args ); foreach( $posts as $post ) : $order_data = get_post_meta($post->ID, 'order_data', true); if (!empty($order_data['order_tax'])) : // means someone has posted a manual order. Need to update to new tax string if (strpos($order_data['order_tax'], ':') === false) : $order_data['order_tax_total'] = $order_data['order_tax']; $order_data['order_tax'] = jigoshop_tax::create_custom_tax($order_data['order_total'] - $order_data['order_tax_total'], $order_data['order_tax_total'], $order_data['order_shipping_tax'], $order_data['order_tax_divisor']); else : $tax_array = get_old_taxes_as_array($order_data['order_tax']); $order_data['order_tax'] = jigoshop_tax::array_implode($tax_array); endif; update_post_meta($post->ID, 'order_data', $order_data); endif; endforeach; }
public static function get_tax_for_display($tax_class) { $return = false; if (jigoshop_cart::get_tax_amount($tax_class, false) > 0 && jigoshop_cart::get_tax_rate($tax_class) > 0 || jigoshop_cart::get_tax_rate($tax_class) !== false) { $return = self::$tax->get_tax_class_for_display($tax_class) . ' (' . (double) jigoshop_cart::get_tax_rate($tax_class) . '%) '; // only show estimated tag when customer is on the cart page and no shipping calculator is enabled to be able to change country if (!jigoshop_shipping::show_shipping_calculator() && is_cart()) { $return .= '<small>' . sprintf(__('estimated for: %s', 'jigoshop'), jigoshop_countries::get_country(jigoshop_tax::get_customer_country())) . '</small>'; } } return $return; }
/** * Returns the destination Country and State tax rate */ public function get_tax_destination_rate() { $rates = array(); if ($this->is_taxable() && self::get_options()->get('jigoshop_calc_taxes') == 'yes') { $tax = new jigoshop_tax(); foreach ($tax->get_tax_classes_for_customer() as $tax_class) { if (!in_array($tax_class, $this->get_tax_classes())) { continue; } $rate = $tax->get_rate($tax_class); if ($rate > 0) { $rates[$tax_class] = array('rate' => $rate, 'is_not_compound_tax' => !$tax->is_compound_tax()); } } } return $rates; }
/** * Admin fields * * Loops though the jigoshop options array and outputs each field. * * @since 1.0 * @usedby jigoshop_settings() * * @param array $options List of options to go through and save */ function jigoshop_admin_fields($options) { ?> <div id="tabs-wrap"> <p class="submit"><input name="save" type="submit" value="<?php _e('Save changes','jigoshop') ?>" /></p> <?php $counter = 1; echo '<ul class="tabs">'; foreach ($options as $value) { if ( 'tab' == $value['type'] ) : echo '<li><a href="#'.$value['type'].$counter.'">'.$value['tabname'].'</a></li>'. "\n"; $counter = $counter + 1; endif; } echo '</ul>'; $counter = 1; foreach ($options as $value) : switch($value['type']) : case 'string': ?> <tr> <td class="titledesc"><?php echo $value['name']; ?></td> <td class="forminp"><?php echo $value['desc']; ?></td> </tr> <?php break; case 'tab': echo '<div id="'.$value['type'].$counter.'" class="panel">'; echo '<table class="widefat fixed" style="width:850px; margin-bottom:20px;">'. "\n\n"; break; case 'title': ?><thead><tr><th scope="col" width="200px"><?php echo $value['name'] ?></th><th scope="col" class="desc"><?php if (isset($value['desc'])) echo $value['desc'] ?> </th></tr></thead><?php break; case 'text': ?><tr> <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td> <td class="forminp"><input name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" type="<?php echo $value['type'] ?>" style="<?php echo $value['css'] ?>" value="<?php if ( get_option( $value['id']) !== false && get_option( $value['id']) !== null ) echo get_option( $value['id'] ); else echo $value['std'] ?>" /><br /><small><?php echo $value['desc'] ?></small></td> </tr><?php break; case 'select': ?><tr> <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td> <td class="forminp"><select name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" style="<?php echo $value['css'] ?>"> <?php foreach ($value['options'] as $key => $val) { ?> <option value="<?php echo $key ?>" <?php if (get_option($value['id']) == $key) { ?> selected="selected" <?php } ?>><?php echo ucfirst($val) ?></option> <?php } ?> </select><br /><small><?php echo $value['desc'] ?></small> </td> </tr><?php break; case 'textarea': ?><tr> <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td> <td class="forminp"> <textarea <?php if ( isset($value['args']) ) echo $value['args'] . ' '; ?>name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" style="<?php echo $value['css'] ?>"><?php if (get_option($value['id'])) echo stripslashes(get_option($value['id'])); else echo $value['std']; ?></textarea> <br /><small><?php echo $value['desc'] ?></small> </td> </tr><?php break; case 'tabend': echo '</table></div>'; $counter = $counter + 1; break; case 'single_select_page' : $page_setting = (int) get_option($value['id']); $args = array( 'name' => $value['id'], 'id' => $value['id']. '" style="width: 200px;', 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'selected' => $page_setting); if( isset($value['args']) ) $args = wp_parse_args($value['args'], $args); ?><tr class="single_select_page"> <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td> <td class="forminp"> <?php wp_dropdown_pages($args); ?> <br /><small><?php echo $value['desc'] ?></small> </td> </tr><?php break; case 'single_select_country' : $countries = jigoshop_countries::$countries; $country_setting = (string) get_option($value['id']); if (strstr($country_setting, ':')) : $country = current(explode(':', $country_setting)); $state = end(explode(':', $country_setting)); else : $country = $country_setting; $state = '*'; endif; ?><tr class="multi_select_countries"> <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td> <td class="forminp"><select name="<?php echo $value['id'] ?>" title="Country" style="width: 150px;"> <?php echo jigoshop_countries::country_dropdown_options($country, $state); ?> </select> </td> </tr><?php break; case 'multi_select_countries' : $countries = jigoshop_countries::$countries; asort($countries); $selections = (array) get_option($value['id']); ?><tr class="multi_select_countries"> <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td> <td class="forminp"> <div class="multi_select_countries"><ul><?php if ($countries) foreach ($countries as $key=>$val) : echo '<li><label><input type="checkbox" name="'. $value['id'] .'[]" value="'. $key .'" '; if (in_array($key, $selections)) echo 'checked="checked"'; echo ' />'. $val .'</label></li>'; endforeach; ?></ul></div> </td> </tr><?php break; case 'coupons' : $coupons = new jigoshop_coupons(); $coupon_codes = $coupons->get_coupons(); ?><tr> <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td> <td class="forminp" id="coupon_codes"> <table class="coupon_rows" cellspacing="0"> <thead> <tr> <th><?php _e('Coupon Code', 'jigoshop'); ?></th> <th><?php _e('Coupon Type', 'jigoshop'); ?></th> <th><?php _e('Coupon Amount', 'jigoshop'); ?></th> <th><?php _e('Product ids', 'jigoshop'); ?></th> <th><?php _e('Individual use', 'jigoshop'); ?></th> <th><?php _e('Delete', 'jigoshop'); ?></th> </tr> </thead> <tbody> <?php $i = -1; if ($coupon_codes && is_array($coupon_codes) && sizeof($coupon_codes)>0) foreach( $coupon_codes as $coupon ) : $i++; echo '<tr class="coupon_row"><td><input type="text" value="'.$coupon['code'].'" name="coupon_code['.$i.']" title="'.__('Coupon Code', 'jigoshop').'" placeholder="'.__('Coupon Code', 'jigoshop').'" class="text" /></td><td><select name="coupon_type['.$i.']" title="Coupon Type">'; $discount_types = array( 'fixed_cart' => __('Cart Discount', 'jigoshop'), 'percent' => __('Cart % Discount', 'jigoshop'), 'fixed_product' => __('Product Discount', 'jigoshop') ); foreach ($discount_types as $type => $label) : $selected = ($coupon['type']==$type) ? 'selected="selected"' : ''; echo '<option value="'.$type.'" '.$selected.'>'.$label.'</option>'; endforeach; echo '</select></td><td><input type="text" value="'.$coupon['amount'].'" name="coupon_amount['.$i.']" title="'.__('Coupon Amount', 'jigoshop').'" placeholder="'.__('Coupon Amount', 'jigoshop').'" class="text" /></td><td><input type="text" value="'.implode(', ', $coupon['products']).'" name="product_ids['.$i.']" placeholder="'.__('1, 2, 3', 'jigoshop').'" class="text" /></td><td><label><input type="checkbox" name="individual['.$i.']" '; if (isset($coupon['individual_use']) && $coupon['individual_use']=='yes') echo 'checked="checked"'; echo ' /> '.__('Individual use only', 'jigoshop').'</label></td><td><a href="#" class="remove button">×</a></td></tr>'; endforeach; ?> </tbody> </table> <p><a href="#" class="add button"><?php _e('+ Add Coupon', 'jigoshop'); ?></a></p> </td> </tr> <script type="text/javascript"> /* <![CDATA[ */ jQuery(function() { jQuery('#coupon_codes a.add').live('click', function(){ var size = jQuery('#coupon_codes table.coupon_rows tbody .coupon_row').size(); // Make sure tbody exists var tbody_size = jQuery('#coupon_codes table.coupon_rows tbody').size(); if (tbody_size==0) jQuery('#coupon_codes table.coupon_rows').append('<tbody></tbody>'); // Add the row jQuery('<tr class="coupon_row">\ <td><input type="text" value="" name="coupon_code[' + size + ']" title="<?php _e('Coupon Code', 'jigoshop'); ?>" placeholder="<?php _e('Coupon Code', 'jigoshop'); ?>" class="text" /></td>\ <td><select name="coupon_type[' + size + ']" title="Coupon Type">\ <option value="percent"><?php _e('% Discount', 'jigoshop'); ?></option>\ <option value="fixed_product"><?php _e('Product Discount', 'jigoshop');?></option>\ <option value="fixed_cart"><?php _e('Cart Discount', 'jigoshop'); ?></option>\ </select></td>\ <td><input type="text" value="" name="coupon_amount[' + size + ']" title="<?php _e('Coupon Amount', 'jigoshop'); ?>" placeholder="<?php _e('Coupon Amount', 'jigoshop'); ?>" class="text" /></td>\ <td><input type="text" value="" name="product_ids[' + size + ']" placeholder="<?php _e('1, 2, 3', 'jigoshop'); ?>" class="text" /></td>\ <td><label><input type="checkbox" name="individual[' + size + ']" /> <?php _e('Individual use only', 'jigoshop'); ?></label></td>\ <td><a href="#" class="remove button">×</a></td></tr>').appendTo('#coupon_codes table.coupon_rows tbody'); return false; }); jQuery('#coupon_codes a.remove').live('click', function(){ var answer = confirm("<?php _e('Delete this coupon?', 'jigoshop'); ?>") if (answer) { jQuery('input', jQuery(this).parent().parent()).val(''); jQuery(this).parent().parent().hide(); } return false; }); }); /* ]]> */ </script> <?php break; case 'tax_rates' : $_tax = new jigoshop_tax(); $tax_classes = $_tax->get_tax_classes(); $tax_rates = get_option('jigoshop_tax_rates'); ?><tr> <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td> <td class="forminp" id="tax_rates"> <div class="taxrows"> <?php $i = -1; if ($tax_rates && is_array($tax_rates) && sizeof($tax_rates)>0) foreach( $tax_rates as $rate ) : $i++; echo '<p class="taxrow"><select name="tax_class['.$i.']" title="Tax Class"><option value="">'.__('Standard Rate', 'jigoshop').'</option>'; if ($tax_classes) foreach ($tax_classes as $class) : echo '<option value="'.sanitize_title($class).'"'; if ($rate['class']==sanitize_title($class)) echo 'selected="selected"'; echo '>'.$class.'</option>'; endforeach; echo '</select><select name="tax_country['.$i.']" title="Country">'; jigoshop_countries::country_dropdown_options($rate['country'], $rate['state']); echo '</select><input type="text" class="text" value="'.$rate['rate'].'" name="tax_rate['.$i.']" title="'.__('Rate', 'jigoshop').'" placeholder="'.__('Rate', 'jigoshop').'" maxlength="8" />% <label><input type="checkbox" name="tax_shipping['.$i.']" '; if (isset($rate['shipping']) && $rate['shipping']=='yes') echo 'checked="checked"'; echo ' /> '.__('Apply to shipping', 'jigoshop').'</label><a href="#" class="remove button">×</a></p>'; endforeach; ?> </div> <p><a href="#" class="add button"><?php _e('+ Add Tax Rule', 'jigoshop'); ?></a></p> </td> </tr> <script type="text/javascript"> /* <![CDATA[ */ jQuery(function() { jQuery('#tax_rates a.add').live('click', function(){ var size = jQuery('.taxrows .taxrow').size(); // Add the row jQuery('<p class="taxrow"> \ <select name="tax_class[' + size + ']" title="Tax Class"> \ <option value=""><?php _e('Standard Rate', 'jigoshop'); ?></option><?php $tax_classes = $_tax->get_tax_classes(); if ($tax_classes) foreach ($tax_classes as $class) : echo '<option value="'.sanitize_title($class).'">'.$class.'</option>'; endforeach; ?></select><select name="tax_country[' + size + ']" title="Country"><?php jigoshop_countries::country_dropdown_options('','',true); ?></select><input type="text" class="text" name="tax_rate[' + size + ']" title="<?php _e('Rate', 'jigoshop'); ?>" placeholder="<?php _e('Rate', 'jigoshop'); ?>" maxlength="8" />%\ <label><input type="checkbox" name="tax_shipping[' + size + ']" /> <?php _e('Apply to shipping', 'jigoshop'); ?></label>\ <a href="#" class="remove button">×</a>\ </p>').appendTo('#tax_rates div.taxrows'); return false; }); jQuery('#tax_rates a.remove').live('click', function(){ var answer = confirm("<?php _e('Delete this rule?', 'jigoshop'); ?>"); if (answer) { jQuery('input', jQuery(this).parent()).val(''); jQuery(this).parent().hide(); } return false; }); }); /* ]]> */ </script> <?php break; case "shipping_options" : foreach (jigoshop_shipping::$shipping_methods as $method) : $method->admin_options(); endforeach; break; case "gateway_options" : foreach (jigoshop_payment_gateways::payment_gateways() as $gateway) : $gateway->admin_options(); endforeach; break; endswitch; endforeach; ?> <p class="submit"><input name="save" type="submit" value="<?php _e('Save changes','jigoshop') ?>" /></p> </div> <script type="text/javascript"> jQuery(function() { // Tabs jQuery('ul.tabs').show(); jQuery('ul.tabs li:first').addClass('active'); jQuery('div.panel:not(div.panel:first)').hide(); jQuery('ul.tabs a').click(function(){ jQuery('ul.tabs li').removeClass('active'); jQuery(this).parent().addClass('active'); jQuery('div.panel').hide(); jQuery( jQuery(this).attr('href') ).show(); jQuery.cookie('jigoshop_settings_tab_index', jQuery(this).parent().index('ul.tabs li')) return false; }); <?php if (isset($_COOKIE['jigoshop_settings_tab_index']) && $_COOKIE['jigoshop_settings_tab_index'] > 0) : ?> jQuery('ul.tabs li:eq(<?php echo $_COOKIE['jigoshop_settings_tab_index']; ?>) a').click(); <?php endif; ?> // Countries jQuery('select#jigoshop_allowed_countries').change(function(){ if (jQuery(this).val()=="specific") { jQuery(this).parent().parent().next('tr.multi_select_countries').show(); } else { jQuery(this).parent().parent().next('tr.multi_select_countries').hide(); } }).change(); }); </script> <?php }
private function get_order_tax_array($key) { $array_string = $this->_fetch($key); $divisor = $this->_fetch('order_tax_divisor'); return jigoshop_tax::get_taxes_as_array($array_string, $divisor); }
function jigoshop_process_shop_order_meta($post_id) { $jigoshop_options = Jigoshop_Base::get_options(); $jigoshop_errors = array(); $order = new jigoshop_order($post_id); // Get old data + attributes $data = (array) maybe_unserialize(get_post_meta($post_id, 'order_data', true)); //Get old order items $old_order_items = (array) maybe_unserialize(get_post_meta($post_id, 'order_items', true)); // Add/Replace data to array $customerDetails = array('billing_first_name', 'billing_last_name', 'billing_company', 'billing_euvatno', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_postcode', 'billing_country', 'billing_state', 'billing_email', 'billing_phone', 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_postcode', 'shipping_country', 'shipping_state'); $order_fields = array('shipping_method', 'shipping_service', 'payment_method', 'order_subtotal', 'order_discount_subtotal', 'order_shipping', 'order_discount', 'order_discount_coupons', 'order_tax_total', 'order_shipping_tax', 'order_total', 'order_total_prices_per_tax_class_ex_tax'); /* Pre-fill the customer addresses */ foreach ($customerDetails as $key) { $order_fields[] = $key; /* Checks if this is a new order from "Add Order" button */ if (!empty($_POST['auto_draft']) && !empty($_POST['customer_user']) && empty($_POST[$key])) { $data[$key] = get_user_meta($_POST['customer_user'], $key, true); } } //Check EUVAT Field if (!empty($data['billing_euvatno']) && !empty($data['billing_country'])) { $data['billing_euvatno'] = str_replace(' ', '', $data['billing_euvatno']); } //run stripslashes on all valid fields foreach ($order_fields as $field_name) { if (isset($_POST[$field_name])) { $data[$field_name] = stripslashes($_POST[$field_name]); } } // Sanitize numeric values $data['order_total'] = jigoshop_sanitize_num($data['order_total']); $data['order_subtotal'] = jigoshop_sanitize_num($data['order_subtotal']); // if a shipping or payment methods has changed, update the method title for pretty display if (isset($_POST['shipping_method'])) { $data['shipping_service'] = ''; $shipping_methods = jigoshop_shipping::get_all_methods(); if (!empty($shipping_methods)) { foreach ($shipping_methods as $method) { if ($_POST['shipping_method'] == $method->id) { $data['shipping_service'] = $method->title; } } } } if (isset($_POST['payment_method'])) { $data['payment_method_title'] = ''; $payment_methods = jigoshop_payment_gateways::get_available_payment_gateways(); if (!empty($payment_methods)) { foreach ($payment_methods as $method) { if ($_POST['payment_method'] == $method->id) { $data['payment_method_title'] = $method->title; } } } } // if total tax has been modified from order tax, then create a customized tax array // just for the order. At this point, we no longer know about multiple tax classes. // Even if we used the old tax array data, we still don't know how to break down // the amounts since they're customized. if (isset($data['order_tax_total']) && $order->get_total_tax() != $data['order_tax_total']) { $new_tax = $data['order_tax_total']; $data['order_tax'] = jigoshop_tax::create_custom_tax($data['order_total'] - $data['order_tax_total'], $data['order_tax_total'], $data['order_shipping_tax'], isset($data['order_tax_divisor']) ? $data['order_tax_divisor'] : null); } // Customer update_post_meta($post_id, 'customer_user', (int) $_POST['customer_user']); // Order items $order_items = array(); if (isset($_POST['item_id'])) { $item_id = $_POST['item_id']; $item_variation = $_POST['item_variation_id']; $item_name = $_POST['item_name']; $item_quantity = $_POST['item_quantity']; $item_cost = $_POST['item_cost']; $item_tax_rate = $_POST['item_tax_rate']; for ($i = 0; $i < count($item_id); $i++) { if (!isset($item_id[$i]) || !isset($item_name[$i]) || !isset($item_quantity[$i]) || !isset($item_cost[$i]) || !isset($item_tax_rate[$i])) { continue; } $variation_id = ''; $variation = ''; if (!empty($item_variation[$i])) { $variation_id = (int) $item_variation[$i]; // if this is a variation, we should check if it is an old one // and copy the 'variation' field describing details of variation foreach ($old_order_items as $old_item_index => $old_item) { if ($old_item['variation_id'] == $variation_id) { $variation = $old_item['variation']; unset($old_order_items[$old_item_index]); break; } } // override variation with values from $_POST if (isset($_POST['order_attributes'][$i]) && is_array($_POST['order_attributes'][$i])) { foreach ($_POST['order_attributes'][$i] as $var_key => $var_value) { $variation[$var_key] = $var_value; } } } $cost_inc_tax = $jigoshop_options->get('jigoshop_prices_include_tax') == 'yes' ? number_format((double) jigowatt_clean($item_cost[$i]), 2, '.', '') : -1; $order_items[] = apply_filters('update_order_item', array('id' => htmlspecialchars(stripslashes($item_id[$i])), 'variation_id' => $variation_id, 'variation' => $variation, 'name' => htmlspecialchars(stripslashes($item_name[$i])), 'qty' => (int) $item_quantity[$i], 'cost' => number_format((double) jigowatt_clean($item_cost[$i]), 2, '.', ''), 'cost_inc_tax' => $cost_inc_tax, 'taxrate' => number_format((double) jigowatt_clean($item_tax_rate[$i]), 4, '.', ''))); } } // Process custom attributes added with "jigoshop_order_data_panels" $data = apply_filters("jigoshop_order_data_save", $data, $post_id); // Save update_post_meta($post_id, 'order_data', $data); update_post_meta($post_id, 'order_items', $order_items); // Order status $order->update_status($_POST['order_status']); // Handle button actions if (isset($_POST['reduce_stock']) && $_POST['reduce_stock'] && count($order_items) > 0) { $order->add_order_note(__('Manually reducing stock.', 'jigoshop')); foreach ($order_items as $order_item) { $_product = $order->get_product_from_item($order_item); if ($_product->exists) { if ($_product->managing_stock()) { $old_stock = $_product->stock; $new_quantity = $_product->reduce_stock($order_item['qty']); $order->add_order_note(sprintf(__('Item #%s stock reduced from %s to %s.', 'jigoshop'), $order_item['id'], $old_stock, $new_quantity)); if ($new_quantity < 0) { if ($old_stock < 0) { $backorder_qty = $order_item['qty']; } else { $backorder_qty = $old_stock - $order_item['qty']; } do_action('jigoshop_product_on_backorder_notification', $post_id, $_product, $backorder_qty); } // stock status notifications if ($jigoshop_options->get('jigoshop_notify_no_stock') == 'yes' && $jigoshop_options->get('jigoshop_notify_no_stock_amount') >= 0 && $jigoshop_options->get('jigoshop_notify_no_stock_amount') >= $new_quantity) { do_action('jigoshop_no_stock_notification', $_product); } else { if ($jigoshop_options->get('jigoshop_notify_low_stock') == 'yes' && $jigoshop_options->get('jigoshop_notify_low_stock_amount') >= $new_quantity) { do_action('jigoshop_low_stock_notification', $_product); } } } } else { $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'jigoshop'), $order_item['id'], $order_item['name'])); } } $order->add_order_note(__('Manual stock reduction complete.', 'jigoshop')); } else { if (isset($_POST['restore_stock']) && $_POST['restore_stock'] && sizeof($order_items) > 0) { $order->add_order_note(__('Manually restoring stock.', 'jigoshop')); foreach ($order_items as $order_item) { $_product = $order->get_product_from_item($order_item); if ($_product->exists) { if ($_product->managing_stock()) { $old_stock = $_product->stock; $new_quantity = $_product->increase_stock($order_item['qty']); $order->add_order_note(sprintf(__('Item #%s stock increased from %s to %s.', 'jigoshop'), $order_item['id'], $old_stock, $new_quantity)); } } else { $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'jigoshop'), $order_item['id'], $order_item['name'])); } } $order->add_order_note(__('Manual stock restore complete.', 'jigoshop')); } else { if (isset($_POST['invoice']) && $_POST['invoice']) { // Mail link to customer jigoshop_send_customer_invoice($order->id); } } } // Error Handling if (count($jigoshop_errors) > 0) { $jigoshop_options->set('jigoshop_errors', $jigoshop_errors); } }
/** Process the checkout after the confirm order button is pressed */ function process_checkout() { global $wpdb; do_action('jigoshop_before_checkout_process'); if (isset($_POST) && $_POST && !isset($_POST['login'])) : jigoshop_cart::calculate_totals(); jigoshop::verify_nonce('process_checkout'); if (sizeof(jigoshop_cart::$cart_contents)==0) : jigoshop::add_error( sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage →</a>','jigoshop'), home_url()) ); endif; // Checkout fields $this->posted['shiptobilling'] = isset($_POST['shiptobilling']) ? jigowatt_clean($_POST['shiptobilling']) : ''; $this->posted['payment_method'] = isset($_POST['payment_method']) ? jigowatt_clean($_POST['payment_method']) : ''; $this->posted['shipping_method'] = isset($_POST['shipping_method']) ? jigowatt_clean($_POST['shipping_method']) : ''; $this->posted['order_comments'] = isset($_POST['order_comments']) ? jigowatt_clean($_POST['order_comments']) : ''; $this->posted['terms'] = isset($_POST['terms']) ? jigowatt_clean($_POST['terms']) : ''; $this->posted['createaccount'] = isset($_POST['createaccount']) ? jigowatt_clean($_POST['createaccount']) : ''; $this->posted['account-username'] = isset($_POST['account-username']) ? jigowatt_clean($_POST['account-username']) : ''; $this->posted['account-password'] = isset($_POST['account-password']) ? jigowatt_clean($_POST['account-password']) : ''; $this->posted['account-password-2'] = isset($_POST['account-password-2']) ? jigowatt_clean($_POST['account-password-2']) : ''; if (jigoshop_cart::ship_to_billing_address_only()) $this->posted['shiptobilling'] = 'true'; // Billing Information foreach ($this->billing_fields as $field) : $this->posted[$field['name']] = isset($_POST[$field['name']]) ? jigowatt_clean($_POST[$field['name']]) : ''; // Format if (isset($field['format'])) switch ( $field['format'] ) : case 'postcode' : $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break; endswitch; // Required if ( isset($field['required']) && $field['required'] && empty($this->posted[$field['name']]) ) jigoshop::add_error( $field['label'] . __(' (billing) is a required field.','jigoshop') ); // Validation if (isset($field['validate']) && !empty($this->posted[$field['name']])) switch ( $field['validate'] ) : case 'phone' : if (!jigoshop_validation::is_phone( $this->posted[$field['name']] )) : jigoshop::add_error( $field['label'] . __(' (billing) is not a valid number.','jigoshop') ); endif; break; case 'email' : if (!jigoshop_validation::is_email( $this->posted[$field['name']] )) : jigoshop::add_error( $field['label'] . __(' (billing) is not a valid email address.','jigoshop') ); endif; break; case 'postcode' : if (!jigoshop_validation::is_postcode( $this->posted[$field['name']], $_POST['billing-country'] )) : jigoshop::add_error( $field['label'] . __(' (billing) is not a valid postcode/ZIP.','jigoshop') ); else : $this->posted[$field['name']] = jigoshop_validation::format_postcode( $this->posted[$field['name']], $_POST['billing-country'] ); endif; break; endswitch; endforeach; // Shipping Information if (jigoshop_cart::needs_shipping() && !jigoshop_cart::ship_to_billing_address_only() && empty($this->posted['shiptobilling'])) : foreach ($this->shipping_fields as $field) : if (isset( $_POST[$field['name']] )) $this->posted[$field['name']] = jigowatt_clean($_POST[$field['name']]); else $this->posted[$field['name']] = ''; // Format if (isset($field['format'])) switch ( $field['format'] ) : case 'postcode' : $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break; endswitch; // Required if ( isset($field['required']) && $field['required'] && empty($this->posted[$field['name']]) ) jigoshop::add_error( $field['label'] . __(' (shipping) is a required field.','jigoshop') ); // Validation if (isset($field['validate']) && !empty($this->posted[$field['name']])) switch ( $field['validate'] ) : case 'postcode' : if (!jigoshop_validation::is_postcode( $this->posted[$field['name']], $this->posted['shipping-country'] )) : jigoshop::add_error( $field['label'] . __(' (shipping) is not a valid postcode/ZIP.','jigoshop') ); else : $this->posted[$field['name']] = jigoshop_validation::format_postcode( $this->posted[$field['name']], $this->posted['shipping-country'] ); endif; break; endswitch; endforeach; endif; if (is_user_logged_in()) : $this->creating_account = false; elseif (isset($this->posted['createaccount']) && $this->posted['createaccount']) : $this->creating_account = true; elseif ($this->must_create_account) : $this->creating_account = true; else : $this->creating_account = false; endif; if ($this->creating_account && !$user_id) : if ( empty($this->posted['account-username']) ) jigoshop::add_error( __('Please enter an account username.','jigoshop') ); if ( empty($this->posted['account-password']) ) jigoshop::add_error( __('Please enter an account password.','jigoshop') ); if ( $this->posted['account-password-2'] !== $this->posted['account-password'] ) jigoshop::add_error( __('Passwords do not match.','jigoshop') ); // Check the username if ( !validate_username( $this->posted['account-username'] ) ) : jigoshop::add_error( __('Invalid email/username.','jigoshop') ); elseif ( username_exists( $this->posted['account-username'] ) ) : jigoshop::add_error( __('An account is already registered with that username. Please choose another.','jigoshop') ); endif; // Check the e-mail address if ( email_exists( $this->posted['billing-email'] ) ) : jigoshop::add_error( __('An account is already registered with your email address. Please login.','jigoshop') ); endif; endif; // Terms if (!isset($_POST['update_totals']) && empty($this->posted['terms']) && get_option('jigoshop_terms_page_id')>0 ) jigoshop::add_error( __('You must accept our Terms & Conditions.','jigoshop') ); if (jigoshop_cart::needs_shipping()) : // Shipping Method $available_methods = jigoshop_shipping::get_available_shipping_methods(); if (!isset($available_methods[$this->posted['shipping_method']])) : jigoshop::add_error( __('Invalid shipping method.','jigoshop') ); endif; endif; if (jigoshop_cart::needs_payment()) : // Payment Method $available_gateways = jigoshop_payment_gateways::get_available_payment_gateways(); if (!isset($available_gateways[$this->posted['payment_method']])) : jigoshop::add_error( __('Invalid payment method.','jigoshop') ); else : // Payment Method Field Validation $available_gateways[$this->posted['payment_method']]->validate_fields(); endif; endif; if (!isset($_POST['update_totals']) && jigoshop::error_count()==0) : $user_id = get_current_user_id(); while (1) : // Create customer account and log them in if ($this->creating_account && !$user_id) : $reg_errors = new WP_Error(); do_action('register_post', $this->posted['billing-email'], $this->posted['billing-email'], $reg_errors); $errors = apply_filters( 'registration_errors', $reg_errors, $this->posted['billing-email'], $this->posted['billing-email'] ); // if there are no errors, let's create the user account if ( !$reg_errors->get_error_code() ) : $user_pass = $this->posted['account-password']; $user_id = wp_create_user( $this->posted['account-username'], $user_pass, $this->posted['billing-email'] ); if ( !$user_id ) { jigoshop::add_error( sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'jigoshop'), get_option('admin_email'))); break; } // Change role wp_update_user( array ('ID' => $user_id, 'role' => 'customer') ) ; // send the user a confirmation and their login details wp_new_user_notification( $user_id, $user_pass ); // set the WP login cookie $secure_cookie = is_ssl() ? true : false; wp_set_auth_cookie($user_id, true, $secure_cookie); else : jigoshop::add_error( $reg_errors->get_error_message() ); break; endif; endif; // Get shipping/billing if ( !empty($this->posted['shiptobilling']) ) : $shipping_first_name = $this->posted['billing-first_name']; $shipping_last_name = $this->posted['billing-last_name']; $shipping_company = $this->posted['billing-company']; $shipping_address_1 = $this->posted['billing-address']; $shipping_address_2 = $this->posted['billing-address-2']; $shipping_city = $this->posted['billing-city']; $shipping_state = $this->posted['billing-state']; $shipping_postcode = $this->posted['billing-postcode']; $shipping_country = $this->posted['billing-country']; elseif ( jigoshop_cart::needs_shipping() ) : $shipping_first_name = $this->posted['shipping-first_name']; $shipping_last_name = $this->posted['shipping-last_name']; $shipping_company = $this->posted['shipping-company']; $shipping_address_1 = $this->posted['shipping-address']; $shipping_address_2 = $this->posted['shipping-address-2']; $shipping_city = $this->posted['shipping-city']; $shipping_state = $this->posted['shipping-state']; $shipping_postcode = $this->posted['shipping-postcode']; $shipping_country = $this->posted['shipping-country']; endif; // Save billing/shipping to user meta fields if ($user_id>0) : update_user_meta( $user_id, 'billing-first_name', $this->posted['billing-first_name'] ); update_user_meta( $user_id, 'billing-last_name', $this->posted['billing-last_name'] ); update_user_meta( $user_id, 'billing-company', $this->posted['billing-company'] ); update_user_meta( $user_id, 'billing-email', $this->posted['billing-email'] ); update_user_meta( $user_id, 'billing-address', $this->posted['billing-address'] ); update_user_meta( $user_id, 'billing-address-2', $this->posted['billing-address-2'] ); update_user_meta( $user_id, 'billing-city', $this->posted['billing-city'] ); update_user_meta( $user_id, 'billing-postcode', $this->posted['billing-postcode'] ); update_user_meta( $user_id, 'billing-country', $this->posted['billing-country'] ); update_user_meta( $user_id, 'billing-state', $this->posted['billing-state'] ); update_user_meta( $user_id, 'billing-phone', $this->posted['billing-phone'] ); if ( empty($this->posted['shiptobilling']) && jigoshop_cart::needs_shipping() ) : update_user_meta( $user_id, 'shipping-first_name', $this->posted['shipping-first_name'] ); update_user_meta( $user_id, 'shipping-last_name', $this->posted['shipping-last_name'] ); update_user_meta( $user_id, 'shipping-company', $this->posted['shipping-company'] ); update_user_meta( $user_id, 'shipping-address', $this->posted['shipping-address'] ); update_user_meta( $user_id, 'shipping-address-2', $this->posted['shipping-address-2'] ); update_user_meta( $user_id, 'shipping-city', $this->posted['shipping-city'] ); update_user_meta( $user_id, 'shipping-postcode', $this->posted['shipping-postcode'] ); update_user_meta( $user_id, 'shipping-country', $this->posted['shipping-country'] ); update_user_meta( $user_id, 'shipping-state', $this->posted['shipping-state'] ); elseif ( $this->posted['shiptobilling'] && jigoshop_cart::needs_shipping() ) : update_user_meta( $user_id, 'shipping-first_name', $this->posted['billing-first_name'] ); update_user_meta( $user_id, 'shipping-last_name', $this->posted['billing-last_name'] ); update_user_meta( $user_id, 'shipping-company', $this->posted['billing-company'] ); update_user_meta( $user_id, 'shipping-address', $this->posted['billing-address'] ); update_user_meta( $user_id, 'shipping-address-2', $this->posted['billing-address-2'] ); update_user_meta( $user_id, 'shipping-city', $this->posted['billing-city'] ); update_user_meta( $user_id, 'shipping-postcode', $this->posted['billing-postcode'] ); update_user_meta( $user_id, 'shipping-country', $this->posted['billing-country'] ); update_user_meta( $user_id, 'shipping-state', $this->posted['billing-state'] ); endif; endif; // Create Order (send cart variable so we can record items and reduce inventory). Only create if this is a new order, not if the payment was rejected last time. $_tax = new jigoshop_tax(); $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 meta data $data = array(); $data['billing_first_name'] = $this->posted['billing-first_name']; $data['billing_last_name'] = $this->posted['billing-last_name']; $data['billing_company'] = $this->posted['billing-company']; $data['billing_address_1'] = $this->posted['billing-address']; $data['billing_address_2'] = $this->posted['billing-address-2']; $data['billing_city'] = $this->posted['billing-city']; $data['billing_postcode'] = $this->posted['billing-postcode']; $data['billing_country'] = $this->posted['billing-country']; $data['billing_state'] = $this->posted['billing-state']; $data['billing_email'] = $this->posted['billing-email']; $data['billing_phone'] = $this->posted['billing-phone']; $data['shipping_first_name'] = $shipping_first_name; $data['shipping_last_name'] = $shipping_last_name; $data['shipping_company'] = $shipping_company; $data['shipping_address_1'] = $shipping_address_1; $data['shipping_address_2'] = $shipping_address_2; $data['shipping_city'] = $shipping_city; $data['shipping_postcode'] = $shipping_postcode; $data['shipping_country'] = $shipping_country; $data['shipping_state'] = $shipping_state; $data['shipping_method'] = $this->posted['shipping_method']; $data['payment_method'] = $this->posted['payment_method']; $data['order_subtotal'] = number_format(jigoshop_cart::$subtotal_ex_tax, 2, '.', ''); $data['order_shipping'] = number_format(jigoshop_cart::$shipping_total, 2, '.', ''); $data['order_discount'] = number_format(jigoshop_cart::$discount_total, 2, '.', ''); $data['order_tax'] = number_format(jigoshop_cart::$tax_total, 2, '.', ''); $data['order_shipping_tax'] = number_format(jigoshop_cart::$shipping_tax_total, 2, '.', ''); $data['order_total'] = number_format(jigoshop_cart::$total, 2, '.', ''); // Cart items $order_items = array(); foreach (jigoshop_cart::$cart_contents as $item_id => $values) : $_product = $values['data']; // Calc item tax to store $rate = ''; if ( $_product->is_taxable()) : $rate = $_tax->get_rate( $_product->data['tax_class'] ); endif; $order_items[] = array( 'id' => $item_id, 'name' => $_product->get_title(), 'qty' => (int) $values['quantity'], 'cost' => $_product->get_price_excluding_tax(), 'taxrate' => $rate ); // Check stock levels if ($_product->managing_stock()) : if (!$_product->is_in_stock() || !$_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 apologise for any inconvenience caused.', 'jigoshop'), $_product->get_title() ) ); break; endif; else : if (!$_product->is_in_stock()) : 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 apologise for any inconvenience caused.', 'jigoshop'), $_product->get_title() ) ); break; endif; endif; endforeach; if (jigoshop::error_count()>0) break; // Insert or update the post data if (isset($_SESSION['order_awaiting_payment']) && $_SESSION['order_awaiting_payment'] > 0) : $order_id = (int) $_SESSION['order_awaiting_payment']; $order_data['ID'] = $order_id; wp_update_post( $order_data ); else : $order_id = wp_insert_post( $order_data ); if (is_wp_error($order_id)) : jigoshop::add_error( 'Error: Unable to create order. Please try again.' ); break; endif; endif; // 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); // Inserted successfully do_action('jigoshop_new_order', $order_id); if (jigoshop_cart::needs_payment()) : // Store Order ID in session so it can be re-used after payment failure $_SESSION['order_awaiting_payment'] = $order_id; // Process Payment $result = $available_gateways[$this->posted['payment_method']]->process_payment( $order_id ); // Redirect to success/confirmation/payment page if ($result['result']=='success') : if (is_ajax()) : ob_clean(); echo json_encode($result); exit; else : wp_safe_redirect( $result['redirect'] ); exit; endif; endif; else : // No payment was required for order $order->payment_complete(); // Empty the Cart jigoshop_cart::empty_cart(); // Redirect to success/confirmation/payment page if (is_ajax()) : ob_clean(); echo json_encode( array('redirect' => get_permalink(get_option('jigoshop_thanks_page_id'))) ); exit; else : wp_safe_redirect( get_permalink(get_option('jigoshop_thanks_page_id')) ); exit; endif; endif; // Break out of loop break; endwhile; endif; // If we reached this point then there were errors if (is_ajax()) : ob_clean(); jigoshop::show_messages(); exit; else : jigoshop::show_messages(); endif; endif; }
function jigoshop_admin_option_display($options) { if (empty($options)) { return false; } $counter = 1; foreach ($options as $value) { switch ($value['type']) { case 'string': ?> <tr> <th scope="row"><?php echo $value['name']; ?> </th> <td><?php echo $value['desc']; ?> </td> </tr><?php break; case 'tab': ?> <div id="<?php echo $value['type'] . $counter; ?> " class="panel"> <table class="form-table"><?php break; case 'title': ?> <thead> <tr> <th scope="col" colspan="2"> <h3 class="title"><?php echo $value['name']; ?> </h3> <?php if (!empty($value['desc'])) { ?> <p><?php echo $value['desc']; ?> </p> <?php } ?> </th> </tr> </thead><?php break; case 'button': ?> <tr> <th scope="row"<?php if (empty($value['name'])) { ?> style="padding-top:0px;"<?php } ?> > <?php if (!empty($value['tip'])) { ?> <a href="#" tip="<?php echo $value['tip']; ?> " class="tips" tabindex="99" ></a> <?php } ?> <?php if (!empty($value['name'])) { ?> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo $value['name']; ?> </label> <?php } ?> </th> <td<?php if (empty($value['name'])) { ?> style="padding-top:0px;"<?php } ?> > <a id="<?php echo esc_attr($value['id']); ?> " class="button <?php if (!empty($value['class'])) { echo esc_attr($value['class']); } ?> " style="<?php if (!empty($value['css'])) { echo esc_attr($value['css']); } ?> " href="<?php if (!empty($value['href'])) { echo esc_attr($value['href']); } ?> " ><?php if (!empty($value['desc'])) { echo $value['desc']; } ?> </a> </td> </tr><?php break; case 'checkbox': ?> <tr> <th scope="row"<?php if (empty($value['name'])) { ?> style="padding-top:0px;"<?php } ?> > <?php if (!empty($value['tip'])) { ?> <a href="#" tip="<?php echo $value['tip']; ?> " class="tips" tabindex="99" ></a> <?php } ?> <?php if (!empty($value['name'])) { ?> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo $value['name']; ?> </label> <?php } ?> </th> <td<?php if (empty($value['name'])) { ?> style="padding-top:0px;"<?php } ?> > <input id="<?php echo esc_attr($value['id']); ?> " type="checkbox" class="jigoshop-input jigoshop-checkbox <?php if (!empty($value['class'])) { echo esc_attr($value['class']); } ?> " style="<?php if (!empty($value['css'])) { echo esc_attr($value['css']); } ?> " name="<?php echo esc_attr($value['id']); ?> " <?php if (get_option($value['id']) !== false && get_option($value['id']) !== null) { echo checked(get_option($value['id']), 'yes', false); } else { if (isset($value['std'])) { echo checked($value['std'], 'yes', false); } } ?> /> <label for="<?php echo esc_attr($value['id']); ?> "><?php if (!empty($value['desc'])) { echo $value['desc']; } ?> </label> </td> </tr><?php break; case 'text': case 'number': ?> <tr> <th scope="row"<?php if (empty($value['name'])) { ?> style="padding-top:0px;"<?php } ?> > <?php if (!empty($value['tip'])) { ?> <a href="#" tip="<?php echo $value['tip']; ?> " class="tips" tabindex="99"></a> <?php } ?> <?php if (!empty($value['name'])) { ?> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo $value['name']; ?> </label> <?php } ?> </th> <td<?php if (empty($value['name'])) { ?> style="padding-top:0px;"<?php } ?> > <input name="<?php echo esc_attr($value['id']); ?> " id="<?php echo esc_attr($value['id']); ?> " type="<?php echo $value['type']; ?> " <?php if ($value['type'] == 'number' && !empty($value['restrict']) && is_array($value['restrict'])) { ?> min="<?php echo isset($value['restrict']['min']) ? $value['restrict']['min'] : ''; ?> " max="<?php echo isset($value['restrict']['max']) ? $value['restrict']['max'] : ''; ?> " step="<?php echo isset($value['restrict']['step']) ? $value['restrict']['step'] : 'any'; ?> " <?php } ?> class="regular-text <?php if (!empty($value['class'])) { echo esc_attr($value['class']); } ?> " style="<?php if (!empty($value['css'])) { echo esc_attr($value['css']); } ?> " placeholder="<?php if (!empty($value['placeholder'])) { echo esc_attr($value['placeholder']); } ?> " value="<?php if (get_option($value['id']) !== false && get_option($value['id']) !== null) { echo esc_attr(get_option($value['id'])); } else { if (isset($value['std'])) { echo esc_attr($value['std']); } } ?> " /> <?php if (!empty($value['desc']) && (!empty($value['name']) && empty($value['group']))) { ?> <br /><small><?php echo $value['desc']; ?> </small> <?php } elseif (!empty($value['desc'])) { ?> <?php echo $value['desc']; ?> <?php } ?> </td> </tr><?php break; case 'select': ?> <tr> <th scope="row"<?php if (empty($value['name'])) { ?> style="padding-top:0px;"<?php } ?> > <?php if (!empty($value['tip'])) { ?> <a href="#" tip="<?php echo $value['tip']; ?> " class="tips" tabindex="99"></a> <?php } ?> <?php if (!empty($value['name'])) { ?> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo $value['name']; ?> </label> <?php } ?> </th> <td> <select name="<?php echo esc_attr($value['id']); ?> " id="<?php echo esc_attr($value['id']); ?> " style="<?php if (isset($value['css'])) { echo esc_attr($value['css']); } ?> " class="<?php if (!empty($value['class'])) { echo esc_attr($value['class']); } ?> " <?php if (!empty($value['multiple'])) { echo 'multiple="multiple"'; } ?> <?php if (!empty($value['class']) && $value['class'] == 'chzn-select' && !empty($value['placeholder'])) { ?> data-placeholder="<?php _e(esc_attr($value['placeholder'])); ?> " <?php } ?> > <?php $selected = get_option($value['id']); $selected = !empty($selected) ? $selected : $value['std']; ?> <?php foreach ($value['options'] as $key => $val) { ?> <option value="<?php echo esc_attr($key); ?> " <?php if (!is_array($selected) && $selected == $key || is_array($selected) && in_array($key, $selected)) { ?> selected="selected" <?php } ?> > <?php echo ucfirst($val); ?> </option> <?php } ?> </select> <?php if (!empty($value['desc']) && (!empty($value['name']) && empty($value['group']))) { ?> <br /><small><?php echo $value['desc']; ?> </small> <?php } elseif (!empty($value['desc'])) { ?> <?php echo $value['desc']; ?> <?php } ?> </td> </tr><?php break; case 'radio': ?> <tr> <th scope="row"<?php if (empty($value['name'])) { ?> style="padding-top:0px;"<?php } ?> > <?php if (!empty($value['tip'])) { ?> <a href="#" tip="<?php echo $value['tip']; ?> " class="tips" tabindex="99"></a> <?php } ?> <?php echo $value['name']; ?> </th> <td<?php if (empty($value['name'])) { ?> style="padding-top:0px;"<?php } ?> > <?php foreach ($value['options'] as $key => $val) { ?> <label class="radio"> <input type="radio" name="<?php echo esc_attr($value['id']); ?> " id="<?php echo esc_attr($key); ?> " value="<?php echo esc_attr($key); ?> " class="<?php if (!empty($value['class'])) { echo esc_attr($value['class']); } ?> " <?php if (get_option($value['id']) == $key) { ?> checked="checked" <?php } ?> > <?php echo esc_attr(ucfirst($val)); ?> </label><br /> <?php } ?> </td> </tr><?php break; case 'image_size': $sizes = array('jigoshop_shop_tiny' => 'jigoshop_use_wordpress_tiny_crop', 'jigoshop_shop_thumbnail' => 'jigoshop_use_wordpress_thumbnail_crop', 'jigoshop_shop_small' => 'jigoshop_use_wordpress_catalog_crop', 'jigoshop_shop_large' => 'jigoshop_use_wordpress_featured_crop'); $altSize = $sizes[$value['id']]; ?> <tr> <th scope="row"><?php echo $value['name']; ?> </label></th> <td valign="top" style="line-height:25px;height:25px;"> <input name="<?php echo esc_attr($value['id']); ?> _w" id="<?php echo esc_attr($value['id']); ?> _w" type="number" min="0" style="width:60px;" placeholder=<?php if (!empty($value['placeholder'])) { echo $value['placeholder']; } ?> value="<?php if ($size = get_option($value['id'] . '_w')) { echo $size; } else { echo $value['std']; } ?> " /> <label for="<?php echo esc_attr($value['id']); ?> _h">x</label> <input name="<?php echo esc_attr($value['id']); ?> _h" id="<?php echo esc_attr($value['id']); ?> _h" type="number" min="0" style="width:60px;" placeholder=<?php if (!empty($value['placeholder'])) { echo $value['placeholder']; } ?> value="<?php if ($size = get_option($value['id'] . '_h')) { echo $size; } else { echo $value['std']; } ?> " /> <input id="<?php echo esc_attr($altSize); ?> " type="checkbox" class="jigoshop-input jigoshop-checkbox" name="<?php echo esc_attr($altSize); ?> " <?php if (get_option($altSize) !== false && get_option($altSize) !== null) { echo checked(get_option($altSize), 'yes', false); } ?> /> <label for="<?php echo esc_attr($altSize); ?> "> <?php echo __('Crop', 'jigoshop'); ?> </label> <br /><small><?php echo $value['desc']; ?> </small> </td> </tr><?php break; case 'textarea': ?> <tr> <th scope="row"><?php if ($value['tip']) { ?> <a href="#" tip="<?php echo $value['tip']; ?> " class="tips" tabindex="99"></a><?php } ?> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo $value['name']; ?> </label></th> <td> <textarea <?php if (isset($value['args'])) { echo $value['args'] . ' '; } ?> name="<?php echo esc_attr($value['id']); ?> " id="<?php echo esc_attr($value['id']); ?> " class="large-text <?php if (!empty($value['class'])) { echo esc_attr($value['class']); } ?> " style="<?php echo esc_attr($value['css']); ?> " placeholder="<?php if (!empty($value['placeholder'])) { echo esc_attr($value['placeholder']); } ?> " ><?php echo esc_textarea(get_option($value['id']) ? stripslashes(get_option($value['id'])) : $value['std']); ?> </textarea> <br /><small><?php echo $value['desc']; ?> </small> </td> </tr><?php break; case 'tabend': ?> </table></div><?php $counter = $counter + 1; break; case 'single_select_page': $args = array('name' => $value['id'], 'id' => $value['id'] . '" style="width: 200px;', 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'selected' => (int) get_option($value['id'])); if (!empty($value['args'])) { $args = wp_parse_args($value['args'], $args); } ?> <tr class="single_select_page"> <th scope="row"><?php if ($value['tip']) { ?> <a href="#" tip="<?php echo $value['tip']; ?> " class="tips" tabindex="99"></a><?php } ?> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo $value['name']; ?> </label></th> <td> <?php wp_dropdown_pages($args); ?> <br /><small><?php echo $value['desc']; ?> </small> </td> </tr><?php break; case 'single_select_country': $countries = jigoshop_countries::$countries; $country_setting = (string) get_option($value['id']); if (strstr($country_setting, ':')) { $country = current(explode(':', $country_setting)); $state = end(explode(':', $country_setting)); } else { $country = $country_setting; $state = '*'; } ?> <tr class="multi_select_countries"> <th scope="row"><?php if ($value['tip']) { ?> <a href="#" tip="<?php echo $value['tip']; ?> " class="tips" tabindex="99"></a><?php } ?> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo $value['name']; ?> </label></th> <td> <select id="<?php echo esc_attr($value['id']); ?> " name="<?php echo esc_attr($value['id']); ?> " title="Country" style="width: 150px;"> <?php $show_all = $value['id'] != 'jigoshop_default_country'; echo jigoshop_countries::country_dropdown_options($country, $state, false, $show_all); ?> </select> </td> </tr><?php if (!$show_all && jigoshop_countries::country_has_states($country) && $state == '*') { jigoshop_countries::base_country_notice(); } break; case 'multi_select_countries': $countries = jigoshop_countries::$countries; asort($countries); $selections = (array) get_option($value['id']); ?> <tr class="multi_select_countries"> <th scope="row"><?php if ($value['tip']) { ?> <a href="#" tip="<?php echo $value['tip']; ?> " class="tips" tabindex="99"></a><?php } ?> <label><?php echo $value['name']; ?> </label></th> <td> <div class="multi_select_countries"> <ul><?php if ($countries) { foreach ($countries as $key => $val) { ?> <li><label> <input type="checkbox" name="<?php echo esc_attr($value['id']) . '[]'; ?> " value="<?php echo esc_attr($key); ?> " <?php if (in_array($key, $selections)) { ?> checked="checked" <?php } ?> /> <?php echo $val; ?> </label></li><?php } } ?> </ul> </div> </td> </tr><?php break; case 'coupons': _deprecated_argument('jigoshop_admin_option_display', '1.3', 'The coupons type has no alternative. Use the new custom post Coupons Menu item under Jigoshop.'); $coupons = new jigoshop_coupons(); $coupon_codes = $coupons->get_coupons(); ?> <style> table{max-width:100%;background-color:transparent;border-collapse:collapse;border-spacing:0;} .table{width:100%;margin-bottom:18px;} .table th,.table td{padding:8px;line-height:18px;text-align:left;vertical-align:top;border-top:1px solid #dddddd;} .table thead th{vertical-align:bottom;} .table caption+thead tr:first-child th,.table caption+thead tr:first-child td,.table colgroup+thead tr:first-child th,.table colgroup+thead tr:first-child td,.table thead:first-child tr:first-child th,.table thead:first-child tr:first-child td{border-top:0;} .table tbody+tbody{border-top:2px solid #dddddd;} .table-condensed th,.table-condensed td{padding:4px 5px;} .coupon-table th,.coupon-table td{padding:8px;line-height:18px;text-align:left;vertical-align:top;border-top:0px;} </style> <tr><td><a href="#" class="add button" id="add_coupon"><?php _e('+ Add Coupon', 'jigoshop'); ?> </a></td></tr> <table class="coupons table"> <thead> <tr> <th>Coupon</th> <th>Type</th> <th>Amount</th> <th>Usage</th> <th>Controls</th> </tr> </thead> <tbody> <?php /* Payment methods. */ $payment_methods = array(); $available_gateways = jigoshop_payment_gateways::get_available_payment_gateways(); if (!empty($available_gateways)) { foreach ($available_gateways as $id => $info) { $payment_methods[$id] = $info->title; } } /* Coupon types. */ $discount_types = jigoshop_coupons::get_coupon_types(); /* Product categories. */ $categories = get_terms('product_cat', array('hide_empty' => false)); $coupon_cats = array(); foreach ($categories as $category) { $coupon_cats[$category->term_id] = $category->name; } $i = -1; if ($coupon_codes && is_array($coupon_codes) && sizeof($coupon_codes) > 0) { foreach ($coupon_codes as $coupon) { $i++; ?> <tr> <td style="width:500px;"> <table class="coupon-table form-table" id="coupons_table_<?php echo $i; ?> "> <?php echo $coupon['code']; ?> <tbody class="couponDisplay" id="coupons_rows_<?php echo $i; ?> "> <?php $selected_type = ''; foreach ($discount_types as $type => $label) { if ($coupon['type'] == $type) { $selected_type = $type; } } $options3 = array(array('name' => __('Code', 'jigoshop'), 'tip' => __('The coupon code a customer enters on the cart or checkout page.', 'jigoshop'), 'id' => 'coupon_code[' . esc_attr($i) . ']', 'css' => 'width:150px;', 'class' => 'coupon_code', 'type' => 'text', 'std' => esc_attr($coupon['code'])), array('name' => __('Type', 'jigoshop'), 'tip' => __('Cart - Applies to whole cart<br/>Product - Applies to individual products only. You must specify individual products.', 'jigoshop'), 'id' => 'coupon_type[' . esc_attr($i) . ']', 'css' => 'width:200px;', 'type' => 'select', 'std' => $selected_type, 'options' => $discount_types), array('name' => __('Amount', 'jigoshop'), 'tip' => __('Amount this coupon is worth. If it is a percentange, just include the number without the percentage sign.', 'jigoshop'), 'id' => 'coupon_amount[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => esc_attr($coupon['amount'])), array('name' => __('Usage limit', 'jigoshop'), 'desc' => __(sprintf('Times used: %s', !empty($coupon['usage']) ? $coupon['usage'] : '0'), 'jigoshop'), 'placeholder' => __('No limit', 'jigoshop'), 'tip' => __('Control how many times this coupon may be used.', 'jigoshop'), 'id' => 'usage_limit[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => !empty($coupon['usage_limit']) ? $coupon['usage_limit'] : ''), array('name' => __('Order subtotal', 'jigoshop'), 'placeholder' => __('No min', 'jigoshop'), 'desc' => __('Min', 'jigoshop'), 'tip' => __('Set the required subtotal for this coupon to be valid on an order.', 'jigoshop'), 'id' => 'order_total_min[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => !empty($coupon['order_total_min']) ? $coupon['order_total_min'] : '', 'group' => true), array('desc' => __('Max', 'jigoshop'), 'placeholder' => __('No max', 'jigoshop'), 'id' => 'order_total_max[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => !empty($coupon['order_total_max']) ? $coupon['order_total_max'] : '', 'group' => true), array('name' => __('Payment methods', 'jigoshop'), 'tip' => __('Which payment methods are allowed for this coupon to be effective?', 'jigoshop'), 'id' => 'coupon_pay_methods[' . esc_attr($i) . '][]', 'css' => 'width:200px;', 'class' => 'chzn-select', 'type' => 'select', 'placeholder' => 'Any method', 'multiple' => true, 'std' => !empty($coupon['coupon_pay_methods']) ? $coupon['coupon_pay_methods'] : '', 'options' => $payment_methods)); jigoshop_admin_option_display($options3); ?> <tr> <th scope="row"> <a href="#" tip="<?php _e('Control which products this coupon can apply to.', 'jigoshop'); ?> " class="tips" tabindex="99"></a> <label for="product_ids_<?php echo esc_attr($i); ?> "><?php _e('Products', 'jigoshop'); ?> </label> </th> <td> <select id="product_ids_<?php echo esc_attr($i); ?> " style="width:200px;" name="product_ids[<?php echo esc_attr($i); ?> ][]" style="width:100px" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e('Any product', 'jigoshop'); ?> "> <?php $product_ids = $coupon['products']; if ($product_ids) { foreach ($product_ids as $product_id) { $title = get_the_title($product_id); $sku = get_post_meta($product_id, '_sku', true); if (!$title) { continue; } if (isset($sku) && $sku) { $sku = ' (SKU: ' . $sku . ')'; } echo '<option value="' . $product_id . '" selected="selected">' . $title . $sku . '</option>'; } } ?> </select> <?php _e('Include', 'jigoshop'); ?> </td> </tr> <tr> <th scope="row"></th> <td style="padding-top:0px;"> <select id="exclude_product_ids_<?php echo esc_attr($i); ?> " style="width:200px;" name="exclude_product_ids[<?php echo esc_attr($i); ?> ][]" style="width:100px" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e('Any product', 'jigoshop'); ?> "> <?php if (!empty($coupon['exclude_products'])) { foreach ($coupon['exclude_products'] as $product_id) { $title = get_the_title($product_id); $sku = get_post_meta($product_id, '_sku', true); if (!$title) { continue; } if (isset($sku) && $sku) { $sku = ' (SKU: ' . $sku . ')'; } echo '<option value="' . $product_id . '" selected="selected">' . $title . $sku . '</option>'; } } ?> </select> <?php _e('Exclude', 'jigoshop'); ?> </td> </tr> <?php $options2 = array(array('name' => __('Categories', 'jigoshop'), 'desc' => __('Include', 'jigoshop'), 'tip' => __('Control which categories this coupon can apply to.', 'jigoshop'), 'id' => 'coupon_category[' . esc_attr($i) . '][]', 'type' => 'select', 'multiple' => true, 'std' => !empty($coupon['coupon_category']) ? $coupon['coupon_category'] : '', 'options' => $coupon_cats, 'class' => 'chzn-select', 'css' => 'width:200px;', 'placeholder' => 'Any category', 'group' => true), array('desc' => __('Exclude', 'jigoshop'), 'id' => 'exclude_categories[' . esc_attr($i) . '][]', 'type' => 'select', 'multiple' => true, 'std' => !empty($coupon['exclude_categories']) ? $coupon['exclude_categories'] : '', 'options' => $coupon_cats, 'class' => 'chzn-select', 'css' => 'width:200px;', 'placeholder' => 'Any category', 'group' => true), array('name' => __('Dates allowed', 'jigoshop'), 'desc' => __('From', 'jigoshop'), 'placeholder' => __('Any date', 'jigoshop'), 'tip' => __('Choose between which dates this coupon is enabled.', 'jigoshop'), 'id' => 'coupon_date_from[' . esc_attr($i) . ']', 'css' => 'width:150px;', 'type' => 'text', 'class' => 'date-pick', 'std' => !empty($coupon['date_from']) ? date('Y-m-d', $coupon['date_from']) : '', 'group' => true), array('desc' => __('To', 'jigoshop'), 'placeholder' => __('Any date', 'jigoshop'), 'id' => 'coupon_date_to[' . esc_attr($i) . ']', 'css' => 'width:150px;', 'type' => 'text', 'class' => 'date-pick', 'std' => !empty($coupon['date_to']) ? date('Y-m-d', $coupon['date_to']) : '', 'group' => true), array('name' => __('Misc. settings', 'jigoshop'), 'desc' => 'Prevent other coupons', 'tip' => __('Prevent other coupons from being used while this one is applied to a cart.', 'jigoshop'), 'id' => 'individual[' . esc_attr($i) . ']', 'type' => 'checkbox', 'std' => isset($coupon['individual_use']) && $coupon['individual_use'] == 'yes' ? 'yes' : 'no'), array('desc' => 'Free shipping', 'tip' => __('Show the Free Shipping method on checkout with this enabled.', 'jigoshop'), 'id' => 'coupon_free_shipping[' . esc_attr($i) . ']', 'type' => 'checkbox', 'std' => isset($coupon['coupon_free_shipping']) && $coupon['coupon_free_shipping'] == 'yes' ? 'yes' : 'no')); jigoshop_admin_option_display($options2); ?> </tbody> </table> <script type="text/javascript"> /* <![CDATA[ */ jQuery(function() { jQuery("select#product_ids_<?php echo esc_attr($i); ?> ").ajaxChosen({ method: 'GET', url: '<?php echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php'); ?> ', dataType: 'json', afterTypeDelay: 100, data: { action: 'jigoshop_json_search_products_and_variations', security: '<?php echo wp_create_nonce("search-products"); ?> ' } }, function (data) { var terms = {}; jQuery.each(data, function (i, val) { terms[i] = val; }); return terms; }); jQuery("select#exclude_product_ids_<?php echo esc_attr($i); ?> ").ajaxChosen({ method: 'GET', url: '<?php echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php'); ?> ', dataType: 'json', afterTypeDelay: 100, data: { action: 'jigoshop_json_search_products_and_variations', security: '<?php echo wp_create_nonce("search-products"); ?> ' } }, function (data) { var terms = {}; jQuery.each(data, function (i, val) { terms[i] = val; }); return terms; }); jQuery('.date-pick').datepicker( {dateFormat: 'yy-mm-dd', gotoCurrent: true} ); }); /* ]]> */ </script> </td> <td><?php echo $discount_types[$selected_type]; ?> </td> <td><?php echo !empty($coupon['amount']) ? $coupon['amount'] : ''; ?> </td> <td><?php echo !empty($coupon['usage']) ? $coupon['usage'] : '0'; ?> </td> <td> <a class="toggleCoupon" href="#coupons_rows_<?php echo $i; ?> "><?php _e('Show', 'jigoshop'); ?> </a> / <a href="#" id="remove_coupon_<?php echo esc_attr($i); ?> " class="remove_coupon" title="<?php _e('Delete this Coupon', 'jigoshop'); ?> "><?php _e('Delete', 'jigoshop'); ?> </a> </td> </tr> <?php } } ?> <script type="text/javascript"> jQuery('.couponDisplay').hide(); /* <![CDATA[ */ jQuery(function() { function toggle_coupons() { jQuery('a.toggleCoupon').click(function(e) { e.preventDefault(); jQuery(this).text(jQuery(this).text() == '<?php _e('Show', 'jigoshop'); ?> ' ? '<?php _e('Hide', 'jigoshop'); ?> ' : '<?php _e('Show', 'jigoshop'); ?> '); var id = jQuery(this).attr('href').substr(1); jQuery('#' + id).toggle('slow'); }); } toggle_coupons(); jQuery('#add_coupon').live('click', function(e){ e.preventDefault(); var size = jQuery('.couponDisplay').size(); var new_coupon = '\ <table class="coupon-table form-table" id="coupons_table_' + size + '">\ <tbody class="couponDisplay" id="coupons_rows_[' + size + ']">\ <tr>\ <th scope="row">\ <a href="#" tip="<?php _e('The coupon code a customer enters on the cart or checkout page.', 'jigoshop'); ?> "\ class="tips" tabindex="99"></a>\ <label for="coupon_code[' + size + ']"><?php _e('Code', 'jigoshop'); ?> </label>\ </th>\ <td>\ <input name="coupon_code[' + size + ']" id="coupon_code[' + size + ']" type="text" class="regular-text coupon_code"\ style="width:150px;" placeholder="" value="" />\ <br />\ <small></small>\ </td>\ </tr>\ <tr>\ <th scope="row">\ <a href="#" tip="<?php _e('Cart - Applies to whole cart<br/>Product - Applies to individual products only. You must specify individual products.', 'jigoshop'); ?> "\ class="tips" tabindex="99"></a>\ <label for="coupon_type[' + size + ']"><?php _e('Type', 'jigoshop'); ?> </label>\ </th>\ <td>\ <select name="coupon_type[' + size + ']" id="coupon_type[' + size + ']" style="width:150px;">\ <option value="fixed_cart"><?php _e('Cart Discount', 'jigoshop'); ?> </option>\ <option value="percent"><?php _e('Cart % Discount', 'jigoshop'); ?> </option>\ <option value="fixed_product"><?php _e('Product Discount', 'jigoshop'); ?> </option>\ <option value="percent_product"><?php _e('Product % Discount', 'jigoshop'); ?> </option>\ </select>\ <br />\ <small></small>\ </td>\ </tr>\ <tr>\ <th scope="row">\ <a href="#" tip="<?php _e('Amount this coupon is worth. If it is a percentange, just include the number without the percentage sign.', 'jigoshop'); ?> "\ class="tips" tabindex="99"></a>\ <label for="coupon_amount[' + size + ']"><?php _e('Amount', 'jigoshop'); ?> </label>\ </th>\ <td>\ <input name="coupon_amount[' + size + ']" id="coupon_amount[' + size + ']" type="number" min="0"\ max="" class="regular-text " style="width:60px;" value=""\ />\ <br />\ <small></small>\ </td>\ </tr>\ <tr>\ <th scope="row">\ <a href="#" tip="<?php _e('Control how many times this coupon may be used.', 'jigoshop'); ?> " class="tips"\ tabindex="99"></a>\ <label for="usage_limit[' + size + ']"><?php _e('Usage limit', 'jigoshop'); ?> </label>\ </th>\ <td>\ <input name="usage_limit[' + size + ']" id="usage_limit[' + size + ']" type="number" min="0"\ max="" class="regular-text " style="width:60px;" placeholder="<?php _e('No limit', 'jigoshop'); ?> "\ value="" />\ </td>\ </tr>\ <tr>\ <th scope="row">\ <a href="#" tip="<?php _e('Set the required subtotal for this coupon to be valid on an order.', 'jigoshop'); ?> "\ class="tips" tabindex="99"></a>\ <label for="order_total_min[' + size + ']"><?php _e('Order subtotal', 'jigoshop'); ?> </label>\ </th>\ <td>\ <input name="order_total_min[' + size + ']" id="order_total_min[' + size + ']" type="number"\ min="0" max="" class="regular-text " style="width:60px;" placeholder="<?php _e('No min', 'jigoshop'); ?> "\ value="" /><?php _e('Min', 'jigoshop'); ?> </td>\ </tr>\ <tr>\ <th scope="row" style="padding-top:0px;"></th>\ <td style="padding-top:0px;">\ <input name="order_total_max[' + size + ']" id="order_total_max[' + size + ']" type="number"\ min="0" max="" class="regular-text " style="width:60px;" placeholder="<?php _e('No max', 'jigoshop'); ?> "\ value="" /><?php _e('Max', 'jigoshop'); ?> </td>\ </tr>\ <tr>\ <th scope="row">\ <a href="#" tip="<?php _e('Which payment methods are allowed for this coupon to be effective?', 'jigoshop'); ?> "\ class="tips" tabindex="99"></a>\ <label for="coupon_pay_methods[' + size + '][]"><?php _e('Payment methods', 'jigoshop'); ?> </label>\ </th>\ <td>\ <select name="coupon_pay_methods[' + size + '][]" id="coupon_pay_methods[' + size + '][]" style="width:200px;"\ class="chzn-select" multiple="multiple">\ <?php foreach ($payment_methods as $id => $label) { echo '<option value="' . $id . '">' . $label . '</option>'; } ?> \ </select>\ <br />\ <small></small>\ </td>\ </tr>\ <tr>\ <th scope="row">\ <a href="#" tip="<?php _e('Control which products this coupon can apply to.', 'jigoshop'); ?> " class="tips"\ tabindex="99"></a>\ <label for="product_ids_' + size + '"><?php _e('Products', 'jigoshop'); ?> </label>\ </th>\ <td>\ <select id="product_ids_' + size + '" style="width:200px;" name="product_ids[' + size + '][]"\ style="width:100px" class="ajax_chosen_select_products_and_variations"\ multiple="multiple" data-placeholder="<?php _e('Any product', 'jigoshop'); ?> "></select><?php _e('Include', 'jigoshop'); ?> </td>\ </tr>\ <tr>\ <th scope="row"></th>\ <td style="padding-top:0px;">\ <select id="exclude_product_ids_' + size + '" style="width:200px;" name="exclude_product_ids[' + size + '][]"\ style="width:100px" class="ajax_chosen_select_products_and_variations"\ multiple="multiple" data-placeholder="<?php _e('Any product', 'jigoshop'); ?> "></select><?php _e('Exclude', 'jigoshop'); ?> </td>\ </tr>\ <tr>\ <th scope="row">\ <a href="#" tip="<?php _e('Control which categories this coupon can apply to.', 'jigoshop'); ?> " class="tips"\ tabindex="99"></a>\ <label for="coupon_category[' + size + '][]"><?php _e('Categories', 'jigoshop'); ?> </label>\ </th>\ <td>\ <select name="coupon_category[' + size + '][]" id="coupon_category_' + size + '" style="width:200px;"\ class="chzn-select" multiple="multiple">\ <?php $categories = get_terms('product_cat', array('hide_empty' => false)); foreach ($categories as $category) { echo '<option value="' . $category->term_id . '">' . $category->name . '</option>'; } ?> \ </select><?php _e('Include', 'jigoshop'); ?> </td>\ </tr>\ <tr>\ <th scope="row">\ <label for="exclude_categories[' + size + '][]"></label>\ </th>\ <td>\ <select name="exclude_categories[' + size + '][]" id="exclude_categories_' + size + '" style="width:200px;"\ class="chzn-select" multiple="multiple">\ <?php $categories = get_terms('product_cat', array('hide_empty' => false)); foreach ($categories as $category) { echo '<option value="' . $category->term_id . '">' . $category->name . '</option>'; } ?> \ </select><?php _e('Exclude', 'jigoshop'); ?> </td>\ </tr>\ <tr>\ <th scope="row">\ <a href="#" tip="<?php _e('Choose between which dates this coupon is enabled.', 'jigoshop'); ?> " class="tips"\ tabindex="99"></a>\ <label for="coupon_date_from[' + size + ']"><?php _e('Dates allowed', 'jigoshop'); ?> </label>\ </th>\ <td>\ <input name="coupon_date_from[' + size + ']" id="coupon_date_from[' + size + ']" type="text"\ class="regular-text date-pick" style="width:150px;" placeholder="<?php _e('Any date', 'jigoshop'); ?> "\ value="" /><?php _e('From', 'jigoshop'); ?> </td>\ </tr>\ <tr>\ <th scope="row" style="padding-top:0px;"></th>\ <td style="padding-top:0px;">\ <input name="coupon_date_to[' + size + ']" id="coupon_date_to[' + size + ']" type="text" class="regular-text date-pick"\ style="width:150px;" placeholder="<?php _e('Any date', 'jigoshop'); ?> " value="" /><?php _e('To', 'jigoshop'); ?> </td>\ </tr>\ <tr>\ <th scope="row">\ <a href="#" tip="<?php _e('Prevent other coupons from being used while this one is applied to a cart.', 'jigoshop'); ?> "\ class="tips" tabindex="99"></a>\ <label for="individual[' + size + ']"><?php _e('Misc. settings', 'jigoshop'); ?> </label>\ </th>\ <td>\ <input id="individual[' + size + ']" type="checkbox" class="jigoshop-input jigoshop-checkbox "\ style="" name="individual[' + size + ']" />\ <label for="individual[' + size + ']"><?php _e('Prevent other coupons', 'jigoshop'); ?> </label>\ </td>\ </tr>\ <tr>\ <th scope="row" style="padding-top:0px;">\ <a href="#" tip="<?php _e('Show the Free Shipping method on checkout with this enabled.', 'jigoshop'); ?> "\ class="tips" tabindex="99"></a>\ </th>\ <td style="padding-top:0px;">\ <input id="coupon_free_shipping[' + size + ']" type="checkbox" class="jigoshop-input jigoshop-checkbox "\ style="" name="coupon_free_shipping[' + size + ']" />\ <label for="coupon_free_shipping[' + size + ']"><?php _e('Free shipping', 'jigoshop'); ?> </label>\ </td>\ </tr>\ </tbody>\ </table>\ '; /* Add the table */ jQuery('.coupons.table').before(new_coupon); jQuery('#coupons_table_' + size).hide().fadeIn('slow'); jQuery("select#product_ids_" + size).ajaxChosen({ method: 'GET', url: '<?php echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php'); ?> ', dataType: 'json', afterTypeDelay: 100, data: { action: 'jigoshop_json_search_products_and_variations', security: '<?php echo wp_create_nonce("search-products"); ?> ' } }, function (data) { var terms = {}; jQuery.each(data, function (i, val) { terms[i] = val; }); return terms; }); jQuery("select#exclude_product_ids_" + size).ajaxChosen({ method: 'GET', url: '<?php echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php'); ?> ', dataType: 'json', afterTypeDelay: 100, data: { action: 'jigoshop_json_search_products_and_variations', security: '<?php echo wp_create_nonce("search-products"); ?> ' } }, function (data) { var terms = {}; jQuery.each(data, function (i, val) { terms[i] = val; }); return terms; }); jQuery('a[href="#coupons_rows_'+size+'"]').click(function(e) { e.preventDefault(); jQuery('#coupons_rows_'+size).toggle('slow', function() { // Stuff later? }); }); jQuery(".chzn-select").chosen(); jQuery(".tips").tooltip(); jQuery('.date-pick').datepicker( {dateFormat: 'yy-mm-dd', gotoCurrent: true} ); return false; }); jQuery('a.remove_coupon').live('click', function(){ var answer = confirm("<?php _e('Delete this coupon?', 'jigoshop'); ?> ") if (answer) { jQuery('input', jQuery(this).parent().parent().children()).val(''); jQuery(this).parent().parent().fadeOut(); } return false; }); }); /* ]]> */ </script> <?php break; case 'tax_rates': $_tax = new jigoshop_tax(); $tax_classes = $_tax->get_tax_classes(); $tax_rates = get_option('jigoshop_tax_rates'); $applied_all_states = array(); ?> <tr> <th><?php if ($value['tip']) { ?> <a href="#" tip="<?php echo $value['tip']; ?> " class="tips" tabindex="99"></a><?php } ?> <label><?php echo $value['name']; ?> </label></th> <td id="tax_rates"> <div class="taxrows"> <?php $i = -1; if ($tax_rates && is_array($tax_rates) && sizeof($tax_rates) > 0) { function array_find($needle, $haystack) { foreach ($haystack as $key => $val) { if ($needle == array("label" => $val['label'], "compound" => $val['compound'], 'rate' => $val['rate'], 'shipping' => $val['shipping'], 'is_all_states' => $val['is_all_states'], 'class' => $val['class'])) { return $key; } } return false; } function array_compare($tax_rates) { $after = array(); foreach ($tax_rates as $key => $val) { $first_two = array("label" => $val['label'], "compound" => $val['compound'], 'rate' => $val['rate'], 'shipping' => $val['shipping'], 'is_all_states' => $val['is_all_states'], 'class' => $val['class']); $found = array_find($first_two, $after); if ($found !== false) { $combined = $after[$found]["state"]; $combined2 = $after[$found]["country"]; $combined = !is_array($combined) ? array($combined) : $combined; $combined2 = !is_array($combined2) ? array($combined2) : $combined2; $after[$found] = array_merge($first_two, array("state" => array_merge($combined, array($val['state'])), "country" => array_merge($combined2, array($val['country'])))); } else { $after = array_merge($after, array(array_merge($first_two, array("state" => $val['state'], "country" => $val['country'])))); } } return $after; } $tax_rates = array_compare($tax_rates); foreach ($tax_rates as $rate) { if ($rate['is_all_states'] && in_array(get_all_states_key($rate), $applied_all_states)) { continue; } $i++; // increment counter after check for all states having been applied echo '<p class="taxrow"> <select name="tax_classes[' . esc_attr($i) . ']" title="Tax Classes"> <option value="*">' . __('Standard Rate', 'jigoshop') . '</option>'; if ($tax_classes) { foreach ($tax_classes as $class) { echo '<option value="' . sanitize_title($class) . '"'; if ($rate['class'] == sanitize_title($class)) { echo 'selected="selected"'; } echo '>' . $class . '</option>'; } } echo '</select> <input type="text" class="text" value="' . esc_attr($rate['label']) . '" name="tax_label[' . esc_attr($i) . ']" title="' . __('Online Label', 'jigoshop') . '" placeholder="' . __('Online Label', 'jigoshop') . '" maxlength="15" />'; echo '<select name="tax_country[' . esc_attr($i) . '][]" title="Country" multiple="multiple" style="width:250px;">'; if ($rate['is_all_states']) { if (is_array($applied_all_states) && !in_array(get_all_states_key($rate), $applied_all_states)) { $applied_all_states[] = get_all_states_key($rate); jigoshop_countries::country_dropdown_options($rate['country'], '*'); //all-states } else { continue; } } else { jigoshop_countries::country_dropdown_options($rate['country'], $rate['state']); } echo '</select> <input type="text" class="text" value="' . esc_attr($rate['rate']) . '" name="tax_rate[' . esc_attr($i) . ']" title="' . __('Rate', 'jigoshop') . '" placeholder="' . __('Rate', 'jigoshop') . '" maxlength="8" />% <label><input type="checkbox" name="tax_shipping[' . esc_attr($i) . ']" '; if (isset($rate['shipping']) && $rate['shipping'] == 'yes') { echo 'checked="checked"'; } echo ' /> ' . __('Apply to shipping', 'jigoshop') . '</label> <label><input type="checkbox" name="tax_compound[' . esc_attr($i) . ']" '; if (isset($rate['compound']) && $rate['compound'] == 'yes') { echo 'checked="checked"'; } echo ' /> ' . __('Compound', 'jigoshop') . '</label> <a href="#" class="remove button">×</a></p>'; } } ?> </div> <p><a href="#" class="add button"><?php _e('+ Add Tax Rule', 'jigoshop'); ?> </a></p> </td> </tr> <script type="text/javascript"> /* <![CDATA[ */ jQuery(function() { jQuery('#tax_rates a.add').live('click', function(){ var size = jQuery('.taxrows .taxrow').size(); // Add the row jQuery('<p class="taxrow"> \ <select name="tax_classes[' + size + ']" title="Tax Classes"> \ <option value="*"><?php _e('Standard Rate', 'jigoshop'); ?> </option><?php $tax_classes = $_tax->get_tax_classes(); if ($tax_classes) { foreach ($tax_classes as $class) { echo '<option value="' . sanitize_title($class) . '">' . $class . '</option>'; } } ?> </select><input type="text" class="text" name="tax_label[' + size + ']" title="<?php _e('Online Label', 'jigoshop'); ?> " placeholder="<?php _e('Online Label', 'jigoshop'); ?> " maxlength="15" />\ </select><select name="tax_country[' + size + '][]" title="Country" multiple="multiple"><?php jigoshop_countries::country_dropdown_options('', '', true); ?> </select><input type="text" class="text" name="tax_rate[' + size + ']" title="<?php _e('Rate', 'jigoshop'); ?> " placeholder="<?php _e('Rate', 'jigoshop'); ?> " maxlength="8" />%\ <label><input type="checkbox" name="tax_shipping[' + size + ']" /> <?php _e('Apply to shipping', 'jigoshop'); ?> </label>\ <label><input type="checkbox" name="tax_compound[' + size + ']" /> <?php _e('Compound', 'jigoshop'); ?> </label><a href="#" class="remove button">×</a>\ </p>').appendTo('#tax_rates div.taxrows'); return false; }); jQuery('#tax_rates a.remove').live('click', function(){ var answer = confirm("<?php _e('Delete this rule?', 'jigoshop'); ?> "); if (answer) { jQuery('input', jQuery(this).parent()).val(''); jQuery(this).parent().hide(); } return false; }); }); /* ]]> */ </script> <?php break; case "shipping_options": foreach (jigoshop_shipping::get_all_methods() as $method) { $method->admin_options(); } break; case "gateway_options": foreach (jigoshop_payment_gateways::payment_gateways() as $gateway) { $gateway->admin_options(); } break; } } }