*
* eg. country = 'CA', state = 'QC', compound = 'yes'* * @param type $a the first object to compare with (our inner array) * @param type $b the second object to compare with (our inner array) * @return int the results of strcmp */ function csort_tax_rates($a, $b) { $str1 = ''; $str2 = ''; $str1 .= $a['country'] . $a['state'] . ($a['compound'] == 'no' ? 'a' : 'b'); $str2 .= $b['country'] . $b['state'] . ($b['compound'] == 'no' ? 'a' : 'b'); return strcmp($str1, $str2); } /** * Update options * * Updates the options on the jigoshop settings page. * * @since 1.0 * @usedby jigoshop_settings() * * @param array $options List of options to go through and save */ function jigoshop_update_options() { global $options_settings; if (isset($_POST['submitted']) && $_POST['submitted'] == 'yes') { $update_image_meta = false; foreach ($options_settings as $value) { if (isset($value['id']) && $value['id'] == 'jigoshop_tax_rates') : $tax_classes = array(); $tax_countries = array(); $tax_rate = array(); $tax_label = array(); $tax_rates = array(); $tax_shipping = array(); $tax_compound = array(); if (isset($_POST['tax_classes'])) : $tax_classes = $_POST['tax_classes']; endif; if (isset($_POST['tax_country'])) : $tax_countries = $_POST['tax_country']; endif; if (isset($_POST['tax_rate'])) : $tax_rate = $_POST['tax_rate']; endif; if (isset($_POST['tax_label'])) : $tax_label = $_POST['tax_label']; endif; if (isset($_POST['tax_shipping'])) : $tax_shipping = $_POST['tax_shipping']; endif; if (isset($_POST['tax_compound'])) : $tax_compound = $_POST['tax_compound']; endif; for ($i = 0; $i < sizeof($tax_classes); $i++) : if (isset($tax_classes[$i]) && isset($tax_countries[$i]) && isset($tax_rate[$i]) && $tax_rate[$i] && is_numeric($tax_rate[$i])) : $country = jigowatt_clean($tax_countries[$i]); $label = trim($tax_label[$i]); $state = '*'; // countries with no states have to have a character for products. Therefore use * $rate = number_format(jigowatt_clean($tax_rate[$i]), 4); $class = jigowatt_clean($tax_classes[$i]); if (isset($tax_shipping[$i]) && $tax_shipping[$i]) $shipping = 'yes'; else $shipping = 'no'; if (isset($tax_compound[$i]) && $tax_compound[$i]) $compound = 'yes'; else $compound = 'no'; // Get state from country input if defined if (strstr($country, ':')) : $cr = explode(':', $country); $country = current($cr); $state = end($cr); endif; if ($state == '*' && jigoshop_countries::country_has_states($country)) : // handle all-states foreach (array_keys(jigoshop_countries::$states[$country]) as $st) : $tax_rates[] = array( 'country' => $country, 'label' => $label, 'state' => $st, 'rate' => $rate, 'shipping' => $shipping, 'class' => $class, 'compound' => $compound, 'is_all_states' => true //determines if admin panel should show 'all_states' ); endforeach; else : $tax_rates[] = array( 'country' => $country, 'label' => $label, 'state' => $state, 'rate' => $rate, 'shipping' => $shipping, 'class' => $class, 'compound' => $compound, 'is_all_states' => false //determines if admin panel should show 'all_states' ); endif; endif; endfor; // apply a custom sort to the tax_rates array. usort($tax_rates, "csort_tax_rates"); update_option($value['id'], $tax_rates); elseif (isset($value['id']) && $value['id'] == 'jigoshop_coupons') : $coupon_code = array(); $coupon_type = array(); $coupon_amount = array(); $product_ids = array(); $date_from = array(); $date_to = array(); $coupons = array(); $individual = array(); if (isset($_POST['coupon_code'])) $coupon_code = $_POST['coupon_code']; if (isset($_POST['coupon_type'])) $coupon_type = $_POST['coupon_type']; if (isset($_POST['coupon_amount'])) $coupon_amount = $_POST['coupon_amount']; if (isset($_POST['product_ids'])) $product_ids = $_POST['product_ids']; if (isset($_POST['coupon_date_from'])) $date_from = $_POST['coupon_date_from']; if (isset($_POST['coupon_date_to'])) $date_to = $_POST['coupon_date_to']; if (isset($_POST['individual'])) $individual = $_POST['individual']; for ($i = 0; $i < sizeof($coupon_code); $i++) : if (isset($coupon_code[$i]) && isset($coupon_type[$i]) && isset($coupon_amount[$i])) : $code = jigowatt_clean($coupon_code[$i]); $type = jigowatt_clean($coupon_type[$i]); $amount = jigowatt_clean($coupon_amount[$i]); if (isset($product_ids[$i]) && $product_ids[$i]) $products = array_map('trim', explode(',', $product_ids[$i])); else $products = array(); if (isset($date_from[$i]) && $date_from[$i]) : $from_date = strtotime($date_from[$i]); else : $from_date = 0; endif; if (isset($date_to[$i]) && $date_to[$i]) : $to_date = strtotime($date_to[$i]) + (60 * 60 * 24 - 1); else : $to_date = 0; endif; if (isset($individual[$i]) && $individual[$i]) : $individual_use = 'yes'; else : $individual_use = 'no'; endif; if ($code && $type && $amount) : $coupons[$code] = array( 'code' => $code, 'amount' => $amount, 'type' => $type, 'products' => $products, 'date_from' => $from_date, 'date_to' => $to_date, 'individual_use' => $individual_use ); endif; endif; endfor; update_option($value['id'], $coupons); elseif (isset($value['type']) && $value['type'] == 'multi_select_countries') : // Get countries array if (isset($_POST[$value['id']])) $selected_countries = $_POST[$value['id']]; else $selected_countries = array(); update_option($value['id'], $selected_countries); /* price separators get a special treatment as they should allow a spaces (don't trim) */ elseif (isset($value['id']) && ( $value['id'] == 'jigoshop_price_thousand_sep' || $value['id'] == 'jigoshop_price_decimal_sep' )): if (isset($_POST[$value['id']])) { update_option($value['id'], $_POST[$value['id']]); } else { @delete_option($value['id']); } /* default back to standard image sizes if no value is entered */ elseif (isset($value['type']) && $value['type']=='image_size') : if(isset($value['id']) && isset($_POST[$value['id'].'_w'])) { update_option($value['id'].'_w', jigowatt_clean($_POST[$value['id'].'_w'])); update_option($value['id'].'_h', jigowatt_clean($_POST[$value['id'].'_h'])); } else { update_option($value['id'].'_w', $value['std']); update_option($value['id'].'_h', $value['std']); } else: if (isset($value['id']) && isset($_POST[$value['id']])) { update_option($value['id'], jigowatt_clean($_POST[$value['id']])); } else { @delete_option($value['id']); } endif; } if ($update_image_meta) { // reset the image sizes to generate the new metadata jigoshop_set_image_sizes(); $posts = get_posts('post_type=product&post_status=publish&posts_per_page=-1'); foreach ((array) $posts as $post) { $images = get_children("post_parent={$post->ID}&post_type=attachment&post_mime_type=image"); foreach ((array) $images as $image) { $fullsizepath = get_attached_file($image->ID); if (false !== $fullsizepath || file_exists($fullsizepath)) { $metadata = wp_generate_attachment_metadata($image->ID, $fullsizepath); if (!is_wp_error($metadata) && !empty($metadata)) { wp_update_attachment_metadata($image->ID, $metadata); } } } } } do_action('jigoshop_update_options'); echo '
* country = 'CA', state = 'QC', compound = 'no'
* * will be sorted to have
* country = 'CA', state = 'QC', compound = 'no'
* country = 'CA', state = 'QC', compound = 'yes'
*
' . __('Your settings have been saved.', 'jigoshop') . '
: |
|
||||||||||||||||
: | |||||||||||||||||
: |
|
||||||||||||||||
: |
|
||||||||||||||||
: |
|
||||||||||||||||
: | |||||||||||||||||
: |
|
||||||||||||||||
: |
|
||||||||||||||||
: |
0)
foreach ($tax_rates as $rate) :
if ($rate['is_all_states']) :
if (in_array($rate['country'], $applied_all_states)) :
continue;
endif;
endif;
$i++;// increment counter after check for all states having been applied
echo '
'; echo '% × '; endforeach; ?> |