Skip to content

Commit

Permalink
Prevent notices on upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Dec 5, 2012
1 parent a0c4c22 commit b152995
Showing 1 changed file with 60 additions and 58 deletions.
118 changes: 60 additions & 58 deletions admin/includes/updates/woocommerce-update-2.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,78 +94,80 @@
$loop = 0;
$tax_rates = get_option( 'woocommerce_tax_rates' );

foreach ( $tax_rates as $tax_rate ) {

foreach ( $tax_rate['countries'] as $country => $states ) {

$states = array_reverse( $states );

foreach ( $states as $state ) {

if ( $state == '*' )
$state = '';

$wpdb->insert(
$wpdb->prefix . "woocommerce_tax_rates",
array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => $tax_rate['rate'],
'tax_rate_name' => $tax_rate['label'],
'tax_rate_priority' => 1,
'tax_rate_compound' => $tax_rate['compound'] == 'yes' ? 1 : 0,
'tax_rate_shipping' => $tax_rate['shipping'] == 'yes' ? 1 : 0,
'tax_rate_order' => $loop,
'tax_rate_class' => $tax_rate['class']
)
);

$loop++;
if ( $tax_rates )
foreach ( $tax_rates as $tax_rate ) {

foreach ( $tax_rate['countries'] as $country => $states ) {

$states = array_reverse( $states );

foreach ( $states as $state ) {

if ( $state == '*' )
$state = '';

$wpdb->insert(
$wpdb->prefix . "woocommerce_tax_rates",
array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => $tax_rate['rate'],
'tax_rate_name' => $tax_rate['label'],
'tax_rate_priority' => 1,
'tax_rate_compound' => $tax_rate['compound'] == 'yes' ? 1 : 0,
'tax_rate_shipping' => $tax_rate['shipping'] == 'yes' ? 1 : 0,
'tax_rate_order' => $loop,
'tax_rate_class' => $tax_rate['class']
)
);

$loop++;
}
}
}
}

$local_tax_rates = get_option( 'woocommerce_local_tax_rates' );

foreach ( $local_tax_rates as $tax_rate ) {

$location_type = $tax_rate['location_type'] == 'postcode' ? 'postcode' : 'city';

if ( $tax_rate['state'] == '*' )
$tax_rate['state'] = '';

$wpdb->insert(
$wpdb->prefix . "woocommerce_tax_rates",
array(
'tax_rate_country' => $tax_rate['country'],
'tax_rate_state' => $tax_rate['state'],
'tax_rate' => $tax_rate['rate'],
'tax_rate_name' => $tax_rate['label'],
'tax_rate_priority' => 2,
'tax_rate_compound' => $tax_rate['compound'] == 'yes' ? 1 : 0,
'tax_rate_shipping' => $tax_rate['shipping'] == 'yes' ? 1 : 0,
'tax_rate_order' => $loop,
'tax_rate_class' => $tax_rate['class']
)
);
if ( $local_tax_rates )
foreach ( $local_tax_rates as $tax_rate ) {

$tax_rate_id = $wpdb->insert_id;
$location_type = $tax_rate['location_type'] == 'postcode' ? 'postcode' : 'city';

foreach ( $tax_rate['locations'] as $location ) {
if ( $tax_rate['state'] == '*' )
$tax_rate['state'] = '';

$wpdb->insert(
$wpdb->prefix . "woocommerce_tax_rate_locations",
$wpdb->prefix . "woocommerce_tax_rates",
array(
'location_code' => $location,
'tax_rate_id' => $tax_rate_id,
'location_type' => $location_type,
'tax_rate_country' => $tax_rate['country'],
'tax_rate_state' => $tax_rate['state'],
'tax_rate' => $tax_rate['rate'],
'tax_rate_name' => $tax_rate['label'],
'tax_rate_priority' => 2,
'tax_rate_compound' => $tax_rate['compound'] == 'yes' ? 1 : 0,
'tax_rate_shipping' => $tax_rate['shipping'] == 'yes' ? 1 : 0,
'tax_rate_order' => $loop,
'tax_rate_class' => $tax_rate['class']
)
);

}
$tax_rate_id = $wpdb->insert_id;

$loop++;
}
foreach ( $tax_rate['locations'] as $location ) {

$wpdb->insert(
$wpdb->prefix . "woocommerce_tax_rate_locations",
array(
'location_code' => $location,
'tax_rate_id' => $tax_rate_id,
'location_type' => $location_type,
)
);

}

$loop++;
}

update_option( 'woocommerce_tax_rates_backup', $tax_rates );
update_option( 'woocommerce_local_tax_rates_backup', $local_tax_rates );
Expand Down

0 comments on commit b152995

Please sign in to comment.