wc_update_200_taxrates

The WooCommerce wc update 200 taxrates function.

Description

wc_update_200_taxrates(); 

Usage

  1. if ( !function_exists( 'wc_update_200_taxrates' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-update-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wc_update_200_taxrates(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-update-functions.php  
  1. function wc_update_200_taxrates() { 
  2. global $wpdb; 
  3.  
  4. // Update tax rates 
  5. $loop = 0; 
  6. $tax_rates = get_option( 'woocommerce_tax_rates' ); 
  7.  
  8. if ( $tax_rates ) 
  9. foreach ( $tax_rates as $tax_rate ) { 
  10.  
  11. foreach ( $tax_rate['countries'] as $country => $states ) { 
  12.  
  13. $states = array_reverse( $states ); 
  14.  
  15. foreach ( $states as $state ) { 
  16.  
  17. if ( '*' == $state ) { 
  18. $state = ''; 
  19.  
  20. $wpdb->insert( 
  21. $wpdb->prefix . "woocommerce_tax_rates",  
  22. array( 
  23. 'tax_rate_country' => $country,  
  24. 'tax_rate_state' => $state,  
  25. 'tax_rate' => $tax_rate['rate'],  
  26. 'tax_rate_name' => $tax_rate['label'],  
  27. 'tax_rate_priority' => 1,  
  28. 'tax_rate_compound' => ( 'yes' === $tax_rate['compound'] ) ? 1 : 0,  
  29. 'tax_rate_shipping' => ( 'yes' === $tax_rate['shipping'] ) ? 1 : 0,  
  30. 'tax_rate_order' => $loop,  
  31. 'tax_rate_class' => $tax_rate['class'],  
  32. ); 
  33.  
  34. $loop++; 
  35.  
  36. $local_tax_rates = get_option( 'woocommerce_local_tax_rates' ); 
  37.  
  38. if ( $local_tax_rates ) 
  39. foreach ( $local_tax_rates as $tax_rate ) { 
  40.  
  41. $location_type = ( 'postcode' === $tax_rate['location_type'] ) ? 'postcode' : 'city'; 
  42.  
  43. if ( '*' == $tax_rate['state'] ) { 
  44. $tax_rate['state'] = ''; 
  45.  
  46. $wpdb->insert( 
  47. $wpdb->prefix . "woocommerce_tax_rates",  
  48. array( 
  49. 'tax_rate_country' => $tax_rate['country'],  
  50. 'tax_rate_state' => $tax_rate['state'],  
  51. 'tax_rate' => $tax_rate['rate'],  
  52. 'tax_rate_name' => $tax_rate['label'],  
  53. 'tax_rate_priority' => 2,  
  54. 'tax_rate_compound' => ( 'yes' === $tax_rate['compound'] ) ? 1 : 0,  
  55. 'tax_rate_shipping' => ( 'yes' === $tax_rate['shipping'] ) ? 1 : 0,  
  56. 'tax_rate_order' => $loop,  
  57. 'tax_rate_class' => $tax_rate['class'],  
  58. ); 
  59.  
  60. $tax_rate_id = $wpdb->insert_id; 
  61.  
  62. if ( $tax_rate['locations'] ) { 
  63. foreach ( $tax_rate['locations'] as $location ) { 
  64.  
  65. $wpdb->insert( 
  66. $wpdb->prefix . "woocommerce_tax_rate_locations",  
  67. array( 
  68. 'location_code' => $location,  
  69. 'tax_rate_id' => $tax_rate_id,  
  70. 'location_type' => $location_type,  
  71. ); 
  72.  
  73.  
  74. $loop++; 
  75.  
  76. update_option( 'woocommerce_tax_rates_backup', $tax_rates ); 
  77. update_option( 'woocommerce_local_tax_rates_backup', $local_tax_rates ); 
  78. delete_option( 'woocommerce_tax_rates' ); 
  79. delete_option( 'woocommerce_local_tax_rates' );